Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

DllNotFoundException when C# code tries to pinvoke a native lib

EgorboEgorbo
edited July 2016 in Questions And Answers

I have an UWP C# project that uses a native lib (my-lib.dll) written in C++ for UWP. The my-lib.dll is added to the C# project as a Content with "Copy always", and when I call a method with [DllImport("my-lib")] - it works fine for Desktop UWP (local machine) but when I deploy it to a HoloLense emulator -- it crashes with DllNotFoundException (Unable to load DLL 'my-lib': The specified module could not be found. (Exception from HRESULT: 0x8007007E)) on that pinvoke. Is there something I forgot to do with my-lib.dll? Thanks in advance.

But it looks like it's there because this code:
var hasNativeLib = (await Package.Current.InstalledLocation.GetFilesAsync()).Any(f => f.Name == "my-lib.dll")
returns true when deployed to Hololens emulator

Lib:
my-lib.dll is a dynamic library x86 compiled via default UWP C++ template.

Environment:
VS2015 UPDATE 3, Emulator 10.0.14342.1018. Target & Min Platform: 10.0.10586.0 (in C# and C++).

Best Answer

Answers

  • Options

    Are you sure all the dependencies for your DLL are also deployed with your project?

    Specifically, the C-Runtime DLLs e.g. msvcp140.dll, vccorlib140.dll, etc. since the DllNotFoundException means the target dll or one of its dependencies wasn’t found.

    Your desktop PC has these DLLs installed as part of the Visual Studio Redistributables, but the emulator (and possibly the HoloLens device) do not have the redists and so will hit this error.

  • Options

    Are you sure all the dependencies for your DLL are also deployed with your project?

    Specifically, the C-Runtime DLLs e.g. msvcp140.dll, vccorlib140.dll, etc. since the DllNotFoundException means the target dll or one of its dependencies wasn’t found.

    Your desktop PC has these DLLs installed as part of the Visual Studio Redistributables, but the emulator (and possibly the HoloLens device) do not have the redists and so will hit this error.

  • Options
    EgorboEgorbo
    edited August 2016

    @TimK thanks, Tim! Actually ucrtbased.dll (debug mode) was missing :smile:

  • Options

    @Egorbo said:
    @TimK thanks, Tim! Actually ucrtbased.dll (debug mode) was missing :smile:

    could you tell us how you found out which dll was missing?

Sign In or Register to comment.