views:

16

answers:

1

I have code which require me to Pinvoke into a 3rd party native DLL. The issue is that when I use the Nunit test runner for those tests, the native dll is locked by the nunit processes (nunit.exe and nubit-agent.exe). Thus my post-build copy command fails because of this.

The only way to generate a 'successful build' (includes post-build command) is to first close Nunit, rebuild the project and re-open Nunit (Wash, rinse and repeat). This is becoming tedious and frustrating.

Is there any way to force unit to release all handles onto loaded assemblies? I have poked around the NUnit Settings a bit but to no avail.

Side note: The other thoughts I have had are along the lines of how I am actually using this 3rd party dll ( it's actually the C# SWIG version of QuantLib). So there actually may be issues with the wrapper C# code and the IDisposable pattern used (based on a comment I received on another question).

A: 

You can use the command line option from a tool like unlocker to release all handles. Or you could load the pinvoke functions into a separate app domain and then release the domain.

Edit:

In the second case. When create an AppDomain and then load the assembly that P/Invokes into that domain, but don't load that assembly into the primary App Domain. Then when the testing is finished unload the App Domain. See here for an example. Once the the domain is unloaded the P/Invoked Dlls should be released too.

Preet Sangha
Unlocker crashes Nunit every time. Can you perhaps expand on the second point?
Ahmad