MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Newtonsoft.Serialization exeption with IL2CPP Backend

Open jganser opened this issue 8 years ago • 10 comments

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

jganser avatar Jun 07 '18 15:06 jganser

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

StephenHodgson avatar Jun 07 '18 15:06 StephenHodgson

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.

StephenHodgson avatar Jun 07 '18 15:06 StephenHodgson

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?

keveleigh avatar Jun 15 '18 00:06 keveleigh

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.

jganser avatar Jun 15 '18 07:06 jganser

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

image

keveleigh avatar Jun 15 '18 21:06 keveleigh

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.

XPav avatar Jul 06 '18 21:07 XPav

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

What are you referring to here?

keveleigh avatar Jul 06 '18 21:07 keveleigh

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.

XPav avatar Jul 06 '18 21:07 XPav

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.

XPav avatar Jul 07 '18 02:07 XPav

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

wiwei avatar Apr 11 '19 20:04 wiwei