Menu

#572 AppDomains exception in case of a callback from native c++

open
nobody
framework (182)
6
2007-05-07
2007-03-01
No

I want to use native static C++ libraries in C#.
For that reason I have implemented wrapper classes with C++/CLI.
This project is linked with the static libraries to a (managed) DLL.
This DLL should be tested with NUnit test cases written in C#.
If I run my project as a normal windows application everything works fine.

If I run my tests with NUnit I get the following exception:

---Start exception-----------
An unhandled exception was detected. Since it was most likely thrown on a separate thread, it may or may not have been caused by the current test.

System.ArgumentException: Cannot pass a GCHandle across AppDomains.
Parameter name: handle
at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)

at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at System.Runtime.InteropServices.GCHandle.op_Explicit(IntPtr value)
at gcroot<ManagedStub ^>.->(gcroot<ManagedStub ^>* ) in c:\program files\microsoft visual studio 8\vc\include\msclr\gcroot.h:line 114
at NativeImpl.Action(NativeImpl* ) in c:\temp2\vs2005\clitest\clitest\clitest\cliwrapper\nativeimpl.cpp:line 22
---End exception-----------

The error occurs when a thread started in the native C++ library use a callback to managed code.
In that case the AppDomain of the callback is "nunit-gui.exe".

This is a conflict to the AppDomain "domain-CLIUnitTest.dll" in that runs the test case.

How can I fix that problem?

Discussion

  • Charlie Poole

    Charlie Poole - 2007-03-27

    Logged In: YES
    user_id=586918
    Originator: NO

    Changed this to a bug for further analysis.

     
  • Andreas Kahl

    Andreas Kahl - 2007-05-07
    • labels: --> framework
    • priority: 5 --> 6
     

Log in to post a comment.

MongoDB Logo MongoDB