1

miserable assembly reference

Unity is having trouble finding my DLL. I have a DLL that I'm able to successfully load in visual studio by adding a reference, but I'm still getting errors in Unity.

The DLL is in .NETframework 4.6.1, and I've tried upgrading the unity .NETframework to 4.x, installing the relevant SDK in the visual studio installer, using different versions of unity (2022, 2020, 2019), all no good.

I know the DLL works because I've been able to compile it outside of unity, but my goal for this project is to have it running in unity without hacky IPC.

Here are a few references to other things I've tried that don't work: A reference to the dll could not be added .dll file not accessible https://answers.unity.com/questions/458300/how-to-use-a-external-dll.html

edit1: So I've tried arranging the DLL as described, but that doesn't solve the issue. I think it must be an issue of "compatible binary" is there an easy way to check that?

more details: the DLL I'm having trouble referencing is a wrapper for another DLL, translating between C# and C++, might that be the issue?

please save me stack overflow.

DLLs in the project, .net DLL referencing c++ DLL

make punk
  • 11
  • 4
  • By _"native"_ I assume you mean _pre-compiled .NET assemblies?_ .NET isn't _"native"_ code. You can make C plugins for Unity, which are native. –  Jun 01 '22 at 06:46

1 Answers1

1

To use plugins/pre-compiled assemblies in Unity (native or .NET), you must place the .DLL(s) in the Assets/Plugins folder. You can use child folders for x86 ir x64. I like to include a vendor name too. Tell me more....

e.g.

Assets
|--Plugins
   |--MickyD
      |--MickyD.SoM.Contracts.dll

Assuming it is a compatible binary, Unity will make the contents of the plug-in available to scripts that you define in Unity.

All you need do is to add the appropriate using at the top of your Unity script.

e.g.

using MickyD.SoM.Contracts;
using UnityEngine;
.
.
.
namespace MickyD.FleetDefender.Vehicles
{
    public class PlaneGadget
    {
        private Airspeed _airspeed; // Type defined in pre-compiled assembly
    }
}

If you are using ASMDEFs in your project with overridden includes then you might need to reference the DLL.

See also

  • So I've tried arranging the DLL as described, but that doesn't solve the issue. I think from your post it must be an issue of "compatible binary". – make punk Jun 01 '22 at 20:47
  • @makepunk _"it must be an issue of 'compatible binary'"_ - [Unity supports the **.NET Framework 4.x** up to **.NET Framework 4.8** as well as **.NET Standard 2.1**] (https://docs.unity3d.com/Manual/dotnetProfileSupport.html) so your .NET Framework 4.x DLL theoretically should work unless of course it has dependent DLLs outside of the above. If you have any .NET Core libraries ensure they are .NET Standard 2.1 or lower which is the equivalent of .NET Core library 3.0 or lower. –  Jun 02 '22 at 04:17
  • @makepunk when you drag the DLLs into **Assets\Plugins** does it appear at least in [The Project Window](https://docs.unity3d.com/Manual/ProjectView.html). Tell me that before trying to use it in your Unity scripts and I can help you more –  Jun 02 '22 at 04:18
  • The dlls do appear in the project window, but I think the issue is that the DLL does have dependents outside of .netframework. The DLL I'm trying to reference (CLRWrapper) references sFoundation20 which I believe is in c++. – make punk Jun 02 '22 at 20:21
  • @makepunk ah ok, be sure to copy those too. [Possibly relevant](https://forum.qt.io/topic/96091/need-help-compiling-library). please take note of _["Looks like is solved isn't it? As for , that would be a different question, consider posting it separately."](https://meta.stackoverflow.com/a/253829/585968)_. Consider accepting this answer as I did say _"you must place the .DLL(s) in the Assets/Plugins"_. Thanks –  Jun 03 '22 at 03:49