Solved

Why do I get "A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll" exception

Posted on 2008-06-25
6
1,677 Views
Last Modified: 2008-06-25
Hi guy,
I'm a bit puzzled as to why I'm getting a "A first chance exception ..." when trying to remove an event handler using "RemoveHandler". I this particular case I have five (5) RemoveHandler statments looking identical, but with different parameters, and only the last statement fails.

The app appears to be working fine so I'm just a bit confused.

Any thoughts?

/Michael
0
Comment
Question by:gem56
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21866732
There are too many possibilities to be sure of anything, without more detail.
0
 

Author Comment

by:gem56
ID: 21866990
As part of creating a Form instance I added several event handlers that includes the following statement:
   "AddHandler Me.ParentSection.Panel.Click, AddressOf Me.Sections.ParentForm.DeselectAllSectionsClick"

Then as part of closing that Form I am removing the added event handlers amongst which is the following statement that compliments the AddHandler statement above:
   "RemoveHandler Me.ParentSection.Panel.Click, AddressOf Me.Sections.ParentForm.DeselectAllSectionsClick"

So I wasn't expecting any exceptions because stepping through the code I can't see any empty pointers, etc. so I'm a bit confused.

/Michael
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 21868144
Michael,

Do you have the full stack trace text for the exception?  When the form is closed, is it disposed?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:gem56
ID: 21868840
Sorry, I forgot to say that I get that message only in the IDE Immediate Window and not as a crash.
The Form also closes OK and all looks normal, except for those messages so I was just curious as to whether I should worry about that or not.

/Michael


0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 21869952
I would ignore that exception with a Try/Catch block.
0
 

Author Comment

by:gem56
ID: 21870670
Actually I am using Try/Catch but (stupid me) I forgot to print the ex.Message from the "Catch ex As Exception", I only looked at the output in Immediate Window.

The message in (Catch ex As Exception) has the following message:
"Delegate to an instance method cannot have null 'This'."

That makes sense so, even though I expected all references to be valid, sometimes "Me.Sections.ParentForm' is Nothing and hence the failure.

Thanks for your assistance (as always).

/Michael
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now