# DllNotFoundException (793989)

**URL:** https://discussions.unity.com/t/dllnotfoundexception-793989/793989
**Category:** Unity Editor
**Tags:** Bug
**Created:** [June 2, 2020, 8:21pm UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989 "2020-06-02T20:21:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dershver\_unity](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@dershver\_unity](https://discussions.unity.com/u/dershver_unity)
#### Post date: [June 2, 2020, 8:21pm UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/1 "2020-06-02T20:21:09Z")

</div>

I am testing this code in the Editor. Using Unity 2018 4.23f1. A script has the following lines:  
[DllImport(“ObjLoad”)] // loads C++ DLL  
public static extern int iLoadObjs( IntPtr pcIP, int iPort, out int iObjs, out IntPtr ptVT);

When it executes in the Editor, I get the following:  
Plugins: Failed to load ‘Assets/Plugins/x64/ObjLoad.dll’ with error 'The specified module could not be found.  
DllNotFoundException: ObjLoad

ObjLoad.dll is in the Assets/plugins\x64 folder. It was built in Visual Studio as an x64 DLL.  
It was linked with the /MD option i.e. C Runtime Library DLL.  
As a workaround I tried to link with /MT i.e. static lib. This failed in Visual Studio with a MSB8024 error.  
Any ideas what is causing the DllNotFoundException ?

---

<div class="post-metadata">

### Author: ![DiegoDePalacio1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/diegodepalacio1/32/187922_2.png) [@DiegoDePalacio1](https://discussions.unity.com/u/DiegoDePalacio1)
#### Post date: [June 3, 2020, 2:38am UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/2 "2020-06-03T02:38:52Z")

</div>

Hi @dershver_unity ,

Have you checked that the configuration of the plugin is right, using the [Plugin Inspector](https://docs.unity3d.com/Manual/PluginInspector.html)?

---

<div class="post-metadata">

### Author: ![dershver\_unity](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@dershver\_unity](https://discussions.unity.com/u/dershver_unity)
#### Post date: [June 3, 2020, 5:29pm UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/3 "2020-06-03T17:29:54Z")

</div>

Yes, I did view it in the Inspector. It is an x64 and available for all platforms.  
Is there anything else, I should check ?  
By the way, the DLL was built for UWP in Visual Studio 2019.

---

<div class="post-metadata">

### Author: ![DiegoDePalacio1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/diegodepalacio1/32/187922_2.png) [@DiegoDePalacio1](https://discussions.unity.com/u/DiegoDePalacio1)
#### Post date: [June 4, 2020, 2:29am UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/4 "2020-06-04T02:29:38Z")

</div>

Do you maybe have another dependency from your `ObjLoad.dll` to another DLL that you’re not including?

Maybe you can test first using an almost empty library with a very basic function and check if you can make it work properly within Unity. This will help you to determine if it’s because of the library content or it’s a problem of setup.

Good luck with it!

---

<div class="post-metadata">

### Author: ![dershver\_unity](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@dershver\_unity](https://discussions.unity.com/u/dershver_unity)
#### Post date: [June 4, 2020, 5:32pm UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/5 "2020-06-04T17:32:56Z")

</div>

Thank you for your reply. The DLL is in C++ and does not call any other dll’s except for the standard C runtime dll’s.  
I tried re-installing the VC++ redistributables and I even copied them into Assets\Plugins\x64.  
It still fails.

Anyway, I have finally resolved this issue and I hope this post will save others from many wasted hours.  
I rebuilt the DLL as a Windows DLL instead of UWP. It now works with the editor. This program is intended for the Hololens. Now I am confused because the Hololens uses the UWP platform. Do I need 2 DLL’s, one in editor mode  
and the other for the Hololens ? Maybe the Hololens will run a Windows DLL.  
However, it seems to me there is an issue with Unity not accepting a UWP DLL.  
I did find the following post:

\_\_[c# - Build C++ plugin for Unity - Stack Overflow](https://stackoverflow.com/questions/49793560/build-c-plugin-for-unity?rq=1__)

---

<div class="post-metadata">

### Author: ![DiegoDePalacio1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/diegodepalacio1/32/187922_2.png) [@DiegoDePalacio1](https://discussions.unity.com/u/DiegoDePalacio1)
#### Post date: [June 5, 2020, 2:14am UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/6 "2020-06-05T02:14:56Z")

</div>

I’m glad that you find the way of having your DLL working in Unity!

And thank you for sharing your findings.

On the other hand, even taking into account that a build for Hololens uses UWP, doesn’t necessarily mean that Unity is able to use UWP plugins.

Unity is able to create a UWP build with Hololens as a target device, so my recommendation for you is to make a simple build using your DLL in some way, just for testing purposes.

Then install the build and check if it’s working and using your DLL.

Good luck with your project!

---

<div class="post-metadata">

### Author: ![dershver\_unity](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@dershver\_unity](https://discussions.unity.com/u/dershver_unity)
#### Post date: [June 15, 2020, 8:13pm UTC](https://discussions.unity.com/t/dllnotfoundexception-793989/793989/7 "2020-06-15T20:13:10Z")

</div>

> [@DiegoDePalacio\_1](#):
>
> I’m glad that you find the way of having your DLL working in Unity!
> 
> And thank you for sharing your findings.
> 
> On the other hand, even taking into account that a build for Hololens uses UWP, doesn’t necessarily mean that Unity is able to use UWP plugins.
> 
> Unity is able to create a UWP build with Hololens as a target device, so my recommendation for you is to make a simple build using your DLL in some way, just for testing purposes.
> 
> Then install the build and check if it’s working and using your DLL.
> 
> Good luck with your project!

I finally built the app for the HoloLens. It works fine in the Editor. However,  
on the HoloLens it crashes with the “DLL not found exception.” Should I go back and change the DLL  
to a UWP build ? Or is there some other step that I need to perform to include the DLL in the build.  
It is in the Plugins/x86 folder.
