Mixedrealitytoolkit-unity: Newtonsoft.Serialization exeption with IL2CPP Backend

Created on 7 Jun 2018  路  10Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Overview

Due to an reflection exception for AOT the serialization crashes applications

Current Workaround: Use Newtonsoft.dll for AOT from the unity package: https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
for IL2CPP build

Possible Solution: Add the Newtonsoft.dll for AOT from the unity package: https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
to the included json resources

Expected Behavior

JsonString gets generated

Actual Behavior

Exception flies due to reflection exception

Steps to reproduce

JsonConvert.Serialize(object obj) with IL2CPP build

Unity Editor Version

2018.1

Mixed Reality Toolkit Release Version

05d004f3f6c384fa856172aab00d351168fa478a

Most helpful comment

FWIW, I spent a bit of time and looked at GLTFSerialization. Even stripping out the "serialize" calls, its use of the LINQ to JSON features of Newtonsoft throughout would make it a non-trivial task to replace with a Unity JsonUtility.

So short of going back in time and Unity supporting glTF directly or Microsoft integrating Newtonsoft Json.Net into .Net Standard 1.0, I don't think there's a 100% satisfactory answer lying around.

All 10 comments

Yeah I'm not a fan of the fact we even depend on that newtonsoft dll.

Part of the issue is that the glTF library is the one that has it embedded, and they explicitly made a choice to use the newtonsoft dll instead of the natice unity json utility.

I don't see any instances of JsonConvert.Serialize(object obj). Is this reproducible in the Toolkit, or a side effect of distributing a specific DLL with the Toolkit?

JsonConvert.Serialize(object obj) is not used by the HoloToolkit, but part of the Newtonsoft.dll. As StephenHodgson already mentioned, the HoloToolkit depends on the Newtonsoft.dll for the glTF library.

Since their already is a Json conversion implementation available as soon as one uses the HoloToolkit, one might use that for it's own application as well. Meaning to Convert some object wo a Json format with the mentioned method.

But when using it AND building for IL2CPP, their is a reflection problem because IL2CPP is an ahead of time compilation.

Hope that answers your question keveleigh.

Looking through to figure out the best way to resolve this, but do you mean JsonConvert.SerializeObject?

image

MRTK depending on glTF depending on Json.Net for the sake of 5 lines of code inside MotionControllerVisualizer.cs, for WMR platforms only, is... suboptimal?

I was using Json.net for my own purposes, and didn't care whether it was the one in MRTK or the "normal" one, but neither of those are workable when using IL2CPP. So I use the Unity package referenced above, all is well, but then MRTK complains.

So I deleted all the glTF folders and removed out the 6 lines that were actually using them, because I'm using a Hololens anyway, and now everything is happy.

So I use the Unity package referenced above, all is well, but then MRTK complains.

What are you referring to here?

https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347

It works on the Hololens.

And to clarify, it's not the MRTK that complains, its the glTF's GLTFSerialization's component that wants the other Newtonsoft.Json.

FWIW, I spent a bit of time and looked at GLTFSerialization. Even stripping out the "serialize" calls, its use of the LINQ to JSON features of Newtonsoft throughout would make it a non-trivial task to replace with a Unity JsonUtility.

So short of going back in time and Unity supporting glTF directly or Microsoft integrating Newtonsoft Json.Net into .Net Standard 1.0, I don't think there's a 100% satisfactory answer lying around.

Closing issues older than 180 days. If this is still an issue, please reactivate with recent information.

Was this page helpful?
0 / 5 - 0 ratings