I want to reference Windows.Foundation in my Unity project. I have played with with the Scripting Runtime Version and API Compatibility level to no avail. I am using IL2CPP as the scripting backend (since .NET is being deprecated).
Can someone please help me figure out how to get Unity to recognize Windows.Foundation?
I saw this post which seems related but didn't fix it for me.
Missing System.Media.Capture.Frames namespace
It is referenced automatically when you build to Universal Windows Platform. See this: https://docs.unity3d.com/Manual/IL2CPP-WindowsRuntimeSupport.html
Note, you cannot reference .winmd files in the editor as it uses Mono to power scripting, and Mono does not support referencing or calling into Windows Runtime APIs.
Related
I'm trying to use MongoDB C# driver (2.8.1) in a UWP app built for Hololens using Unity 2019.1.13f1. I read that this driver (which targets .NET 4.x if I'm correct) was fully compatible with UWP apps since Windows SDK 16299. However, even if it works like a charm in Unity Editor, it is not the case when deployed to Hololens (I cannot connect to my database).
I tried to build the project using .NET 4.x API compatibility level and I have granted the app all the necessary capabilities (*InternetClient*, *InternetClientServer*, *PrivateNetworkClientServer*).
This triggered this exception on runtime : Unsupported internal call for IL2CPP:Module::GetPEKind
Then, I tried to change the API compatibility level to .NET Standard 2.0.
This made the above exception disappear but it still does not work...
Do you have any ideas? I might think that this driver is not compatible with Hololens after all...
Thanks in advance
EDIT
After many attempts, I finally got to this conclusion:
MongoDB C# Driver is currently (as of Unity 2019.1.13f1) not compatible with IL2CPP on Hololens because it tries to make an icall not supported by the latter (very specifically when trying to call new MongoClient()).
I was unable to compile my project on Unity 2018.4 using .NET backend (apparently there are huge compatibility problems with this backend and this is why Unity is dropping it).
Honestly, I am not an expert on UWP at all, but as other people have managed to make this driver work as expected with IL2CPP on "normal" UWP devices, I am guessing that this could be related to Hololens software (I know it uses a special build of Windows 10).
After a lot of tinkering I found a way to make the MongoDB C# Driver work with Unity IL2CPP builds (I tested it on PC and UWP builds, but I guess it works for others too)
For it to work I had to make a custom build of the driver, plus pay some attention to other details.
But before I go into a bit of detail of my findings, here's a link to an example project that I uploaded: MongoDB IL2CPP Example Project (don't forget to change the MongoDBTester.cs to use your instance of MongoDB)
So here's what I did:
MongoDB Driver:
In ClientDocumentHelper.cs of the driver source is a function CreateOSDocument() which contains a section #if NET452 - I just removed that whole section and tried it out in Unity with the IL2CPP build and it solved the OPs NotSupportedException
Unity - Assembly Stripping:
The stripping process removed some code that is actually needed, which I fixed with a linker file - link.xml in the Plugins Folder of my example project.
Unity - AOT and Reflections:
The MongoDB Driver uses reflections for some things, like getting the right serializer for a collection. The AOT nature of C++ builds and the way IL2CPP works don't mix well with that (see Unity Docs - Scripting Restrictions).
Fortunately this is easy enough to work around: If you use generic classes (like Dictionary) you need to specify the Serializer with the BsonSerializerAttribute
For constructors the same issue happens when using constructors with arguments - I just ensure that an zero argument public constructor is available for all classes that are used with MongoDB.
Unity - IPv4:
I'm not sure if this has anything to do with Unity or the MongoDB Driver, or maybe just the server why my instance of MongoDB was hosted, but I encountered a problem that my address protocol was not supported. So I wrote a workaround to use IPv4 instead.
Additional Note:
I noticed that auto-mapping of my classes did not always work. I haven't quite figured out when and why it doesn't work but if this happens just manually map the class with BsonClassMap.RegisterClassMap
Hope this helps, let me know if it works for you or if you encounter any other problems.
I have been developing on the Hololens. The project is on .NET 4.x with IL2CPP with API compatibility 4.x. I'm using Unity 2018.3.6f.
I need to add external DLL (IdentityClient.dll)
Reference: IdentityModel NuGet Package
This dll has dependencies on both Newtonsoft.Json and System.Text.Encodings.Web.
After lot of work, I'm now able to deploy my application with the dlls, but when I use them, it makes my application crash. The problem is with Newtonsoft.Json.
Since IL2CPP use AOT compilation and newtonsoft use reflection, it crashes. I've replaced the Newtonsoft.Json.dll with this
https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
I've been able to use Newtonsoft in my code, but the IdentityModel.dll still references the old implementation even though I deleted it. So it crashes again. I'm kind of stuck right now and I'm wondering if any of you would has a solution!
I'm also thinking if I can't fix it too :
Fork the github project of IdentityModel and adjust it
Just make everything manually instead of relaying on IdentityModel, but it will probably take some time.
Moreover, everything works fine in the Unity Editor, but when it's deployed it crash.
In the end, I decided to implement de dll myself. Most people working on Hololens seems to have similar issues
I'm trying to use web services on unity.
I used svcutil to generate a proxy class, however the proxy class was using "System.Threading.Tasks".
I noticed that System.Threading.Tasks wasn't aviable on .Net 3.5.
So I went to player setting and I changed to .Net 4.x
But now I have an other issue, and I cannot find a way to fix it, I need to use System.Web.dll and System.Web.Services.dll to make my web service work, however, the dll that are include in Program Files\Unity\Editor\Data\Mono\lib\mono\2.0 are all targets for .Net 3.5.
So that mean I cannot use them on .Net 4.x
I've been looking for quiet long and was unable to find any answer.
I can add the code to the proxy class here if it's require, but I don't think it would be useful. Should I download those dll somewhere?
Anyone ever seen thoses issues somewhere?
You are using the wrong dll version.
Once you change Api Compatibility Level to Net 4.x, you have to copy the System.Web.dll and System.Web.Services.dll files from <UnityInstallationDirectory>\Editor\Data\MonoBleedingEdge\lib\mono\4.5 to your <Project>\Assets path.
That's it. Restart Visual Studio and Unity.
There is another method of linking missing libraries as described in this unity documentation.
Create a file called csc.rsp and put these 2 lines in it:
-r:System.Web.dll
-r:System.Web.Services.dll
And yes, you better set compatibility level to .NET 4.x
You also might want to restart Unity or VS in some cases.
I'm creating a Monogame UWP Project and whenever I make a call to an included very basic compiled DLL .NET Core library within the project it throws the Error: Could not load file or assembly System.Runtime 4.1.0.0
Here is the project Sample:
http://www.filedropper.com/game1_2
Is everyone else getting the same Error? How do I go about fixing this issue?
Kind regards, Josh L.
As #iinspectable said in the comments:
You cannot reference a full .NET assembly from a UWP project.
UWP is a thing on it's own, and is basically incompatible with .NET as it needs to run on all Win10 platforms (where .NET is meant to be run on Windows PC). Now i don't know monogame, but if it's a .NET Library, it's incompatible with UWP.
I don't have Xamarin yet, and i want to build some application both for android and windows, each will use same shared library.
Is there a possibility to link .NET 4.0 assembly to Xamarin ios/android project, without recompile?
This assembly reference to System only, uses SQLite-NET by praeclarum, which requires native Windows library sqlite3.dll.
As i heard, on Mono/Xamarin? Mono.Data.Sqlite is required instead sqlite3.dll, but i am not sure, can i keep my library "cross-platform" with it? Or i will have to change something?
Unfortunately, i cannot check this currently.
Thank you..
.net assemblies can't be linked to Xamarin Android/iOS but you can link PCLs or you can create a Xamarin Android/iOS project, link files from your .net assemblies there and resolve possible problems with conditional directives (#if...).