MATLAB: Does the callback not trigger or why do I receive an error when the listener on a .NET event is triggered in MATLAB 7.10 (R2010a)

callbackinlistenerMATLABneton

I have loaded a .NET Assembly into MATLAB using NET.addAssembly. Further I added a listener to one of its properties. When the callback is triggered however, I receive the following error:
??? Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source: dotnetcli
HelpLink:
Unexpected error status flag encountered. Resetting to proper state.

Best Answer

This enhancement has been incorporated in Release 2011b (R2011b). For previous product releases, read below for any possible workarounds:
In .NET it is the convention that when working with events to use the following delegate signature:
public delegate void MyEventHandler(object sender, EventArgs args);
MATLAB relies on this first argument "sender" to be the actual object which raised the event. If this is not the case, the callback on the MATLAB side will not be called.
Further, MATLAB assumes that when there are more than one arguments (like "args" in the signature above), that these will not be null. If the second argument is null however, you may receive the error listed above. If you are developing the .NET Assembly yourself and you do not have any real EventArgs to return consider returning an Empty EventArgs instead of null:
MyEvent(this, new EventArgs());
Instead of:
MyEvent(this, null);