Simple unit test for abstract class with p/invoked methods is leaving the unmanaged dll locked when tests are executed. Oddly enough the lock does not happen when debugging the test, only when test is run.
Similar problem here reported on Visual Studio 2012 and I am using a similar workaround, a bit less hacky but nonetheless not a good solution.
Workaround
Added a "teardown" method to be executed once tests terminate to manually free the unmanaged library.
[DllImport("kernel32", SetLastError=true)]
static extern bool FreeLibrary(IntPtr hModule);
[AssemblyCleanup]
public static void Teardown()
{
foreach (ProcessModule mod in Process.GetCurrentProcess().Modules)
{
if (mod.ModuleName == "example.dll")
{
FreeLibrary(mod.BaseAddress);
}
}
}
Aucun commentaire:
Enregistrer un commentaire