9

Background info (might be relevant):

  • Using Unity 2017.2 with "Scripting Runtime Version" set to "Experimental (.NET 4.6 equivalent)"
  • Writing code in Visual Studio 2017 (not MonoDevelop)

I have a Unity project that makes direct use of a third-party DLL ("library A"), which I've added to the project's Assets folder. Library A depends on another DLL, "library B", which I've also added to the Assets folder. Library B is not used by any scripts in the Unity project. Both libraries A and B are written in C# and target .NET 4, i.e., they're both managed code.

Once added to the Assets folder, both libraries A and B are listed under "References" when the project is opened in Visual Studio and "Copy Local" is set to "True" for both (although I don't know if Unity uses that property).

However, when running the project in the Unity editor, various calls to library A raise exceptions that indicate that library B isn't available. The only way I've been able to get it to work is by placing a copy of library B in C:\Program Files\Unity\Editor (the directory containing Unity.exe, the Unity editor executable).

I've used libraries A and B in other, non-Unity projects and never had any issues (Visual Studio copies them both to the output directory as long as they're referenced). Am I missing a Unity-specific step that's necessary to tell it that library B is required?

Reign of Error
  • 577
  • 5
  • 18
  • Have you tried deleting the `Library` folder in your project and re-opening? – BenjaFriend Jun 21 '18 at 16:12
  • @BenjaFriend Thanks for the suggestion; just tried it, but no luck. – Reign of Error Jun 21 '18 at 17:50
  • Incidentally, I tried [this answer](https://stackoverflow.com/a/7856474/2274765) and confirmed that VS 2017 exhibits the same behaviour, but it had no effect on Unity (which probably doesn't use MSBuild). – Reign of Error Jun 22 '18 at 14:47
  • I believe DLLs are supposed to go under Assets/Plugins/ in Unity. **EDIT:** According to the latest documentation, this doesn't appear to be the case. I thought I had seen that somewhere. *shrugs* – LLSv2.0 Feb 19 '20 at 15:57
  • Do you happen to place one of them in FirstPass folders (Plugins), and the other one outside? – Ren Aug 31 '21 at 00:55

4 Answers4

1

I ran into this same issue today, and here's what fixed it for me: In the Unity editor, navigate to where the library B is located, select the library, and on the Inspector window under "Plugin load settings", enable the "Load on startup" checkbox. I suppose this is needed because no Unity scripts are directly calling library B.

Bob
  • 11
  • 1
0

I just wanted to share how i get this done. I'm using Unity 2019.2.10f1 by the way.

I have many of my own and third party managed dll files in my project, and I copy them all to ProjectFolder\Assets\Resources\

and I've never had any problem calling out to any of the libraries, or those libs calling each other.

Maybe the issue is that since your second library (library B) is not referenced by any scripts, Unity is not bundling it and making it available at debug/runtime.

In my experience, I have found that if you want something to be retained in your build, (any unreferenced assets that may be consumed dynamically at runtime), stick it in the Resources subfolder of Assets.

A second option may be to construct some dummy call to the second 'Library B' (that does nothing, perhaps construct and dump), so that Unity thinks that it is needed and includes it in your build.

Not sure if that helps, but Good Luck!

Navil
  • 1
  • 1
0

Unity actually has a special folder called "Plugins" directly under the Assets folder that you can use. This will allow you to add references to dlls made outside of Unity and link against them. You can even have them sorted by targets!

  • Assets/Plugins/x86
  • Assets/Plugins/Android
  • ...

The plugins accepted are all these following extensions: .dll, .winmd, .so, .jar, .aar, .xex, .def, .suprx, .prx, .sprx, .rpl, .cpp, .cc, .c, .h, .jslib, .jspre, .bc, .a, .m, .mm, .swift, .xib, .dylib, .framework, .bundle, .plugin

Unity 2020.3 Plugins Documentation

ExaltedBagel
  • 582
  • 5
  • 14
0

if the DLL from NuGet tries to download this unity package, by using this package you will able to download NuGet packages as a unity package and it will work correctly without any errors.

https://github.com/GlitchEnzo/NuGetForUnity/releases

anas ali
  • 1
  • 1