Problem using a DLL with Unity

Hello everyone,

I’d like to include a third party library into my Unity project. It comes in the form of a number of .NET DLLs, which have inter-dependencies to each other.

Without going into too much detail about my use case, here’s what I can tell you:

  • The DLLs work perfectly in a standalone C# project created by VisualStudio.
  • Unity imported the DLLs into the project without problems and linked them correctly.
  • I can use the types of the Unity-imported assemblies in VisualStudio and MonoDevelop.
  • The code I am writing for my Unity project which uses the assemblies compiles clean in Visual Studio without errors.
  • Loading the DLL dynamically at runtime in Unity works, too.
  • Using .NET Peek, I’ve checked all dependencies. Everything except for mscorlib.dll is there and in the same folder.

Ok, all nice and good, but here’s the catch. When I include the DLLs statically (instead of loading them dynamically and working with reflection all the time), Unity gives me the following compile error:

FileNotFoundException: Could not load file or assembly [name of one of the DLLs I try to use] or one of its dependencies.

This happens in spite of the fact that VisualStudio compiles cleanly. MonoDevelop also compiles the project without problems, it seems that only the Unity Editor has problems with it. And due to this, the code won’t work during runtime either.

Now, the question of course is: Why does this happen? I’ve tried a lot of things, e.g. copying the DLLs next to the .csproj file and also next to the compiled DLLs that Unity generates, but it’s no good - static linking just won’t work! I also already set my Unity compile target to Full .Net Framework 2, without success. I’m really running out of ideas here. Also, the error message is neither very specific nor very helpful…

In case that you want to try it on your own, the library that I’m trying to use is IKVM.

I’d be grateful for any help or advice on this topic.

Thanks,

Alan

Additional info:
It’s a bit old, but this tutorial basically explains what I’m trying to do. Unfortunately, it doesn’t work the way the author describes the process (due to the error stated above): http://www.e-nature.ch/tech/unity-3d-using-java-classescode/
Some further info can be found here, apparently it worked for some people, unfortunately not for me :frowning:

This could be an issue with the way the third party assemblies are compiled. They may be compiled to target x86 for example instead of “Any CPU” or they may be targeting an incorrect version of the framework. One of this is likely a culprit. Also, if you downloaded the DLLs off the interwebs, right click them and go to properties (one at a time) and make sure none of them have execution blocked. If they are blocked, click the “Unblock” button in the properties window to unblock them. This happens sometimes with downloaded assemblies.