开发者

How to force Nunit to release handles on native DLLs?

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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜