views:

220

answers:

2

I am writing a C# unit test to test C++/CLI functionality that involves threads.

The C++/CLI code implements a DirectShow filter, the Windows API for rendering movies. This works thus that I create DirectShow objects, I tell it to run an AVI through my C++/CLI filters, waits until rendering is done, and then exits. My filter has a callback that gives the video frames to C# for processing. DirectShow works thus 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 running a unit test from Resharper it fails with the error "Cannot pass a GCHandle across AppDomains".

What appears to go wrong is that Resharper uses AppDomains in its testrunner, and the DirectShow thread is somehow not associated with this appdomain.

So how do I make this test work from Resharper? Is there a NUnit/Resharper setting to control if appdomains are used? Can I tell the CLR somehow that a thread is assocated with a particular appdomain? Do you know any other pragmatic workarounds?

TIA Jan

+1  A: 

You didn't mention the ReSharper version that you are using. Try running the tests with the latest ReSharper 5.0 Nightly Build. The guys there had rewritten the test runner to support Nunit naively. If this doesn't work, I suggest you report this as an issue at their new Bug Tracking system.

hmemcpy
Thanks for taking the trouble. I managed to fix the root cause in the meantime, but I'll surely test with 5.0 soon enough.
jdv
+1  A: 

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

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

jdv