Paul Wheatley

I'm getting the message "NULLReferenceException: Object reference not set to an instance of an object"

when executing the following:

if (this->mycontrol->InvokeRequired == true)


this->mycontrol->Invoke(gcnew MethodInvoker(this,&myForm::controlDelegate));


The exception refers to the line that calls the Invoke method.

This does not happen consistently. Most of the time there is no exception.

Any suggestions



Re: Visual C++ Language Exception from Invoke method

Holger Grund

Use a debugger to see what's going on.

The first step would be to identify where exactly the exception happens. That may be less than trivial in the C++ managed debugger. However, the _full_ callstack should give you an indication of what's going on.

Taking a look at the callstack of the exception would help. You can either catch the exception in code and take a look at the stacktrace or use the managed (non-C++) debugger and take a look the pseudo register for the current exception ($exception IIRC).