Link to home
Start Free TrialLog in
Avatar of gem56
gem56

asked on

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

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

There are too many possibilities to be sure of anything, without more detail.
Avatar of gem56
gem56

ASKER

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
Michael,

Do you have the full stack trace text for the exception?  When the form is closed, is it disposed?
Avatar of gem56

ASKER

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


ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gem56

ASKER

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