Background
I am using PInvoke to call some native methods, my DllImport declarations look something like this:
public static class Interop
{
internal const string InteropDll = "MyInteropDll";
[DllImport(InteropDll, EntryPoint = "DoSomething")]
internal static extern void DoSomething();
[DllImport(InteropDll, EntryPoint = "DoSomethingElse")]
internal static extern void DoSomethingElse();
}
This assembly gets built and referenced in my Unity3d project and everything works as expected. However, I also created a number of unit tests that indirectly test these methods through a wrapper class. When I run the tests in Visual Studio 2012 using the Visual Studio Unit Testing Framework I get:
A first chance exception of type 'System.DllNotFoundException' occurred in InsituSceneGenerator.dll
Additional information: Unable to load DLL 'SimulationPlugin.API.Unmanaged': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The DLL is present in the unit test output directory, so I added '.dll' to the end of InteropDll to see if that made a difference.
internal const string InteropDll = "MyInteropDll.dll";
Now the unit test passes as expected, but when I run with the change in Unity3d I get the same error, now in a new place:
DllNotFoundException: MyInteropDll.dll
My hunch is that this is a difference between running on the Mono and Microsoft CLR.
Question
Why doesn't my DllImport definition work in both places?
Is there a way that I can define my DllImport so that it works in both places?
I've considered duplicating the definitions in two classes (InteropMs and InteropMono) and selecting which to use at runtime, but I'd rather not do this as a I have a large number of methods (40+ and growing) and I don't want to maintain them in two places.
Aucun commentaire:
Enregistrer un commentaire