Problem Compiling 64bit DLL in Unity

Hello,

I am new to Unity and c# and would be grateful for some help please.

I am using Windows 7, 64bit and Unity 4.1.04f Pro (trial version) with MonoDevelop 2.8.2. I want to use a managed 64bit 3rd party DLL (compiled in c# in .NET framework 4.0) in Unity. I’ve added the 3rd party DLL in the Assets folder and the DLL is clearly shown in References in MonoDevelop. I tried building for the target framework Mono/.NET 4.0 and 3.5 for any CPU platform but getting error "COMException at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (Int32 errorCode) [0x0000d] in Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:1031 "

(BTW, I managed to compile the 32bit version of the 3rd party DLL via [DllImport] but it crashes Unity. I don’t want to use the 32bit version, anyway.)

My code looks something like this:
using UnityEngine;
using 3rdParty;
using System.Runtime.InteropServices;

public class MyClass: MonoBehaviour {

void Start()
{
builder b = new builder(); //this is an object from the 3rd party DLL
b.MethodB(); // this is a method from the 3rd party DLL

}
}
Any idea, please? Thank you!

One thing you need to remember about unity is that its C# scripting and not real .net…
So, I dont know if you can take a libary off the net what was not written to work with unity…

I mean, yes it could be generic enough of a third party dll that may work…
But… Unity is built upon Mono and Mono is a cross platform version of C#…
So not all the .net library are going to work in Mono.

But, do I hope I am wrong and that there is actually a solution to your issue.

Good luck!

Mono is actually a cross platform implementation of .NET. C# is just a language. :slight_smile:

The reason you’re running into issues is because the DLL is compiled to .NET 4.0. Compile it to 3.5 and it should pretty much work (although some things are not implemented in the version of Mono that Unity uses at which time you’ll need to work around those specific cases).