- Home /
how to reference a .NET 4 targeted, native code wrapper assembly in Unity (beta)?
I am trying to use a well known Google.OrTools (https://developers.google.com/optimization/) package in Unity for C#. This contains C# wrappers for a number of graph algos (and other things) implemented in C++, with PInvoke; it requires Mono 4.2.
I tried the recent beta build that allows one to target .NET 4.6 and switched the project to 4.6. When I import Google.Protobuf.dll from the same package, everything is good (and the asset properties say that it targets .NET 4-something).
However, Google.OrTools gets imported as "native" DLL. Is there some fundamental problem with Unity and PInvoke, or is unity just "confused"? Can I force it to consider it a managed DLL somehow? I don't care about any compat at this point.
Also, if I add it to the VS project manually, I cannot build in Unity (reference is not added), but I can build in VS - with warnings that the DLL targets .NET 4 and the project targets .NET 2. It is surprising that 2.0 is the target in VS when 4.6 is chosen in Mono project properties... could this be related, or is it just an orthogonal problem with the .NET 4.6 beta?
You cant use .Net code greater than 2.0 in Unity, if you add to visual studio it will only try use the correct net version that is supported by VS but it don't means that is supported by Unity.
Yes, you can - in the beta. I've successfully imported a regular .NET 4 assembly and used it... however, the native one doesn't work.