.net – Can’t find PInvoke DLL error in Windows Mobile

compact-frameworkemulationnetpinvokewindows-mobile

I am having a lot of trouble getting a basic scenario to work on windows mobile 5.0 emulator. I have a winforms app that eventually calls into native code. Deployment works fine and all the native DLLs are copied in the same folder as the winforms .exe. I also verified this is the case with Remote File Viewer tool.

However when I launch my app, it always fails with "Can't find PInvoke dll — System.MissingMethodException" error (when the time comes to call into native code, the DllImport attribute is rendered useless). I know that the native dll is found in the same folder as the executable. What more should I do?

I am using VS 2008.

Best Answer

To extend Jared's answer, four more common reasons to get a MissingMethodException while P/Invoking in the CF:

  1. You are missing dependencies of the native library you are calling into.
  2. The native assmebly was compiled for the wrong subsystem (i.e. desktop, not CE)
  3. The native assembly was compiled for the wrong processor (i.e. x86 and not ARM)
  4. You don't have enough virtual memory for the DLL to load.

Have you verified the DLL entry points are undecorated with something like dumpbin?

Related Topic