.net unit test failed "Cannot pass GCHandle via AppDomains" when calling from an external thread

I am writing a C # unit test to test the C ++ / CLI functionality, which includes threads.

C ++ / CLI code implements the DirectShow filter, the Windows API for rendering movies. This works in such a way that I create DirectShow objects, I say that it launches AVI through my C ++ / CLI filters, waits until the rendering is complete, and then exits. My filter has a callback that passes video frames to C # for processing. DirectShow works in such a way that it creates its own thread and calls my COM objects from this thread.

Now this stuff works when I run my code normally, but when I run the unit test from Resharper it fails with the error "Unable to pass GCHandle via AppDomains".

Something is wrong, just that Resharper uses AppDomains in its testrunner, and the DirectShow stream is somehow not related to this appdomain.

So, how do I do this test work with Resharper? Is there a NUnit / Resharper parameter to manage if domain applications are used? Can I tell the CLR that the thread is associated with a particular appdomain? Do you know any other pragmatic workarounds?

TIA Jan

+4
source share
2 answers

I managed to get it to work with the procedure described at http://www.lenholgate.com/archives/000856.html

It describes how to make an unmanaged function pointer to a method in a managed class. When you call this function pointer, you end up in a managed application where the object was originally created. This fixes my application errors.

+5
source

You did not mention the version of ReSharper that you are using. Try running the tests with the latest ReSharper 5.0 Nightly Build . The guys there rewrote a test runner to naively support Nunit. If this does not work, I suggest you report it as a problem in my new bug tracking system .

+1
source

Source: https://habr.com/ru/post/1301349/


All Articles