DLL not found with standalone app but works fine in editor

Hi everyone!

I am playing with unity native plugins. However, as the title suggested, I encounter the strange dll not found issue. I only got error when I try to run it as a standalone windows app. From editor, it works fine. And I have verified the dll exist in Appname_Data/Plugin directory in my standalone app.

Some basic information that might help diagnose this issue:
platform: window 8.1
dev tool: vs 2015
The dll (test.dll) is produced by visual studio 2015 (debug and x64). It depends on many other dlls which I copied along with test.dll into my unity project. The dll load perfectly fine if I run the app from unity Editor but failed if build and run it as a standalone 64 bit windows app.

Has anyone seen the same issue before? Is this a bug in Unity or am I doing something wrong?



Could you name what DLLs you copied to your Unity project which were dependencies of your test.dll?

All other dlls are actually produced from the same project. So name them probably wont give you more information? I basically copied all the dlls in the out/ directory of my project to unity's Assets/Plugin/x86 directory. So I shouldn't miss any dlls from my project.
The thing that really strange is why it works fine from Editor but not from standalone app. I dont know what's different in the two runtime environments. And some of the differences is probably why standalone doesnt work.

I'm guessing the reason for it not working on the standalone player is because you have some DLLs in your unity project that your DLL depends on but they're marked as compatible with editor only, so Unity doesn't copy them to your plugins directory of the standalone build.

You could use dependency walker (http://dependencywalker.com/) to figure out which DLL it cannot find (just drop the test.dll from the standalone build into it and it will tell what's missing).


Thanks for the detailed suggestions! Dependency walker told me some dlls indeed missing. But searching on the web and some experiment shows that these dlls might be false positive. The following are reported by dependency walker that are missing:
The first three are reported as missing even for a working dll and dependency walker also returned the same thing for my dll in unity project.

Is the difference between editor and standalone expected? It sounds like unity should give a warning in the case since don't copy them means standalone wont work.

There shouldn't be any differences between standalone player and the editor.

Can you PM me a copy of the DLL? I'd try it tomorrow.

There are about 144 dlls. Let me see if I can reproduce the problem with smaller project.

It looks like if a dll depends on another dll, then the problem occurs. I have locally reproduce the problem with a simple example. Not sure if this ring any bell to you? I can PM you the dlls if you still want them to give a try.
Again, I am using visual studio 2015 and unity 5.3.3 for my test.

If you reproduced it in a simple example, can you zip up and PM me the whole project?

Thanks for sending the project! I reproduced it successfully and I filled a bug report (case 776918).

There is a simple workaround: move all the native DLLs from Data\Plugins to the root folder, next to the executable.

1 Like

Thanks! The workaround works fine for me.

Can you please explain the workaround? Where is the root folder, and what are the native DLL's? I am also facing the exact same issue. Thank you so much!

Root folder is the folder where the game executable is. DLLs are the native plugins that don't load.

By the way, this got fixed in 5.3.4p3.

Hi, rly fixed? I have same problem in 5.4.1f1

DLL works in the editor but not in the player?

Yes, and moving DLLs in root folder helps. I'm using OS X version of Unity (maybe its make difference)

You meant OS X version of the editor, or OS X version of the player?

Editor, of course.

I just tried to reproduce this in 5.4.1f1 and it seems to work fine. Could file a bug report with a repro project? It might have something to do with your plugin setup.

I am using Unity 5.4.1f1 and ViveSoftware's MediaDecoder plugin (https://www.assetstore.unity3d.com/en/#!/content/63938). They provide a sample scene in the plugin, and I have used that. I loaded and saved the project on a Mac. I have built the app on both Mac and Windows. The app works when I run the source code directly in Unity on Windows. If I build it, the DLL search paths get messed up, regardless of where I build it.

A couple of the error messages from the ouput_log:

Fallback handler could not load library D:/Shared/apps/MediaDecoder_Data/Mono/.\D:/Shared/apps/MediaDecoder_Data/Plugins/MediaDecoder.dll

Failed to load 'D:/Shared/apps/MediaDecoder_Data/Plugins/MediaDecoder.dll' with error 'The specified module could not be found.'.

Please note that the search path in the second error message is correct. The DLL is located there, but I guess the app searches in the first, incorrect, search path...