I’m trying to use an external dll with my Unity project. It is a native .net 2.0 library. I’m using MonoDevelop and set up the reference to my dll through ‘Project->Edit References’ and add the .net assembly there. Monodevelop builds fine, but Unity complains about a missing assembly reference.
I read, that other people had this problem and copied the dll into their Assets folder, so I did that. It didn’t help, the error message is still there and Unity just won’t compile my script.
Additionally each time I close and reopen MonoDevelop the reference to the library is gone and I need to add it again. But I shouldn’t even need to add it as a reference if I have the dll in my Assets folder, right?
However as I wrote in my initial post, just dropping it into the Assets folder isn’t working for me. Unity doesn’t set up the reference. So I get the typical “error CS0246: The type or namespace name `Ixxat’ could not be found. Are you missing a using directive or an assembly reference?”
But the assembly is clearly there in the Assets folder. Am I missing something?
This error message is generated by Unity in the console? Where are you putting the assembly and where is the script trying to use the assembly located?
If you ask Unity to regenerate the MonoDevelop solution (via the assets menu), does the assembly correctly show up as a referenced external assembly in the solution?
Should that indeed be the case, we’re running out of runway here. Remaining guesses without more data are basically that either you’re trying to access the wrong namespace - one which is in fact not defined in the assembly at hand - or the assembly is of an incompatible IL version.
Sync MonoDevelop Project also doesn’t make the assembly show up in the solution. If I manually add it as reference beforehand it even makes it disappear again.
What I’m trying to do specifically: I’m trying to communicate with a device over a CAN-to-USB interface:
A .Net API is provided and I’m able to compile sample code in Visual Studio to communicate with the device. But I want to have the data in Unity and since it’s a .Net 2.0 assembly I thought, it should be possible to access it directly from a script in Unity.
Since that didn’t work I wrote a simple C# Wrapper in Visual Studio compiled it to a dll (to get around the namespacing issue). When I tried using that dll in Unity instead, I got an “Unhandled Exception: System.TypeLoadException” error message.
I don’t know if the two problems are related.
Again, I’m glad you’re taking time to look into this, thanks a lot.
Sounds to me like that API DLL is a com wrapper used to access an unmanaged API. It may be trying to load other types via com or reflection that it is unable to load, such as native or .net classes that are not part of unities mono distribution or possibly winapi stuff. My guess though is that it contains or accesses unmanaged code and for some reason can’t be loaded by unity.
The off manual says “The .NET 2.0 API is only used for adaptation to the COM-based programming interface”. It would be a bit of work but you could write a windows service to install alongside your unity app and use that service as a proxy to interface with the driver. Your wrapper would then communicate with the service. Your service would use the API DLL and communicate with the CAN driver.
Ah I see, I should’ve read the manual more carefully.
I feared that this would be the way I need to go to solve this. Thanks for clarifying.
For now I’m using a different approach however. The device doesn’t have to use the CAN communication protocol. I’m now using a serial COM port instead. This takes a bit of redoing work on the hardware side of things but it’s easier to implement in Unity, with .NET SerialPort.
Anyway, thanks a lot for your help, I really appreciate it.
I have the same issue when trying to use LitJson to create an inventory system for my 3D RPG game, I already added the LitJson.dll file into the Assets folder and added LitJson.dll to my visual studio script through references. unity won’t remove 2 errors in the console and because of that I can’t run my scene or create new scripts. Do I also need to use a Com port? and if so, how? are there any other solutions? [USER=393]@AngryAnt@Julien_ @Dustin-Horne
I was getting the same error because I had differing target frameworks between my dll and those specified in the Player settings. Once I matched those up the problem went away.
shit i have got same problem and i have not enough knowledge about coding to solve this problem it is advanced for me my game still run with errors but they are annoying. There should be a way to get rid of that problem i am still searching. maybe i should install 2017 version of unity
Hi! I have created a code library in a “Shared Project” not in an assembly. the shared project works very well in Visual Studio solutions and projects but I don’t know how to use this shared project with unity. shared projects are pure code without any output and get compiled under the referencing project domain. I have added the shared project to the Unity auto-generated solution but the auto-generated Assembly-CSharp project doesn’t recognize it and also the is no Add>reference option for Assembly-CSharp. can I some-how add a reference to my shared project or I must copy-paste all codes and update them manually? Thanks in advance!