Unfortunately, I can't attach test app, beacuse it's too complex.
The error suggests that the GC dispose the delegate which is offered by the managed code to native subsystem.
I think you your solution may be something like this:
Quote:void initnative()
{
   var callbackDelegate = new NativeFunctionManagedSign(nativeCallBack)
   callNativeDllRegisterCallbackFunction( callbackDelegate  );
}
 In this case, first time, the GC dispose the callbackDelegate local variable, but the native DLL don't know about this.
To overcome this, I think the following solution is needed:
Quote:
[static] NativeFunctionManagedSign callbackDelegate;
void initnative()
{
   callbackDelegate = new NativeFunctionManagedSign(nativeCallBack)
   GC.KeepAlive( callbackDelegate );
   GC.SuppressFinalize( this );
   callNativeDll_RegisterCallbackFunction( callbackDelegate  );
}
void donenative()
{
  callNativeDll_deRegisterCallbackFunction();
  callbackDelegate = null;
  
  GC. .....
}
void nativeCallBack( ..... )
{
}