Malfunction Posted July 19, 2004 Posted July 19, 2004 I'm getting a System.NullReferenceException in the following line of code: this.myEvent(this, e); In the debugger window "this" and "e" are not null in fact they are what they're supposed to be: this is of the type myControl and e is of the typeMouseEventArgs - a messageBox before that line of code confirms that. I even removed the parameters from the delegate but this.myEvent(); throws the same exception. I checked every field in the debugger window and still couldn't find the null reference. Quote Debug me...
ilya2 Posted July 19, 2004 Posted July 19, 2004 Maybe your event itself is causing an exception? Quote Ilya
Malfunction Posted July 19, 2004 Author Posted July 19, 2004 How can the event cause an exception? So far there's no event handler catching this event and the debugger always points to that line of code. It's driving me nuts because I can't find a null pointer by the time the exception is thrown. Quote Debug me...
Administrators PlausiblyDamp Posted July 19, 2004 Administrators Posted July 19, 2004 What is this.MyEvent? Could you show where this is declared. If it is a delegate is it assigned anything? Normally when invoking an event handler you need to check if it points to anything. if (myEvent != null){ this.myEvent(this, e);} Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Wile Posted July 19, 2004 Posted July 19, 2004 If nobody subscribed to your event yet (they have to do MyEvent += <delegate_to_eventhandler>), the this.MyEvent object is still null (which is a very annoying feature IMHO). Use the construction above by PlausiblyDamp to handle such a situation. Edit: typo Quote Nothing is as illusive as 'the last bug'.
Malfunction Posted July 19, 2004 Author Posted July 19, 2004 If nobody subscribed to your event yet (they have to do MyEvent += <delegate_to_eventhandler>), the this.MyEvent object is still null (which is a very annoying feature IMHO). Use the construction above by PlausiblyDamp to handle such a situation. Edit: typo thx I really didn't know that ... Quote Debug me...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.