Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

JSON .NET for Unity

Discussion in 'Assets and Asset Store' started by Dustin-Horne, Sep 13, 2013.

  1. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Got it.
     
  2. mmortall

    mmortall

    Joined:
    Dec 28, 2010
    Posts:
    89
    I have crash in latest JSon.Net in Web GL build (Unity 5.3.4f1)

    I use latest JSon.dll from your website for C# 3.5

    My code:
    Code (CSharp):
    1.  
    2. public class TestClass
    3. {
    4.             public TestClass() { }
    5.  
    6.             [JsonProperty]
    7.             private int _LevelStartCount = 0;
    8.  
    9.             [JsonProperty]
    10.             private bool _IsAdvertisementSkiped = false;
    11.  
    12.             [JsonProperty("gold")]
    13.             private int _CurrentGold = 0;
    14. }
    15.  
    16.   public override string SerializeToStringJSon(EType type)
    17.   {
    18.     var testClass = new TestClass();
    19.     var res = JSon.SerializeObject<TestClass>(testClass);
    20.     return res;
    21.     }
    22.  
    23. public static class JSon
    24.   {
    25.   private static JsonSerializerSettings _JSonSettings = new JsonSerializerSettings();
    26.  
    27.   static JSon()
    28.   {
    29.   _JSonSettings.ObjectCreationHandling = ObjectCreationHandling.Replace;
    30.   _JSonSettings.TypeNameHandling = TypeNameHandling.Auto;
    31.   _JSonSettings.TraceWriter = new JSonTraceWriter();
    32.   }
    33.   public static string SerializeObject<T>(T obj)
    34.   {
    35.   var res = JsonConvert.SerializeObject(obj, _JSonSettings);
    36.   return res;
    37.   }
    38.  
    39. }
    40.  
    Error:

    Code (CSharp):
    1.  
    2. Exception at:
    3. Error
    4.   at jsStackTrace (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:1278:13)
    5.   at stackTrace (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:1295:22)
    6.   at blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:108:40
    7.   at __ZN6il2cpp2vm9Exception5RaiseEP15Il2CppException [il2cpp::vm::Exception::Raise(Il2CppException?*)] (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:67002:2)
    8.   at __ZN6il2cpp6icalls8mscorlib6System10Reflection4Emit13DynamicMethod21create_dynamic_methodEP29Il2CppReflectionDynamicMethodS7_ [il2cpp::icalls::mscorlib::System::Reflection::Emit::DynamicMethod::create_dynamic_method?7(Il2CppReflectionDynamicMethod?S?*)] (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:49392:2)
    9.   at _DynamicMethod_CreateDynMethod_m3215158047 (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:3659687:6)
    10.   at _DynamicMethod_CreateDelegate_m2157976338 (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:3659752:3)
    11.   at Array._DynamicReflectionDelegateFactory_CreateDefaultConstructor_TisIl2CppObject_m3118751385_gshared (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:4580887:9)
    12.   at __ZN23GenericVirtFuncInvoker1IP18Func_1_t1531479235P6Type_tE6InvokeEPK10MethodInfoPvS3_ [void undefined<undefined?n?>?o? GenericVirtFuncInvoker1<Type_t?**, undefined?6?>?k()] (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:5093130:39)
    13.   at _DefaultContractResolver_GetDefaultCreator_m3153469439 (blob:https%3A//www.hookwarsonline.com/6d52ed8f-0b29-4cbf-8254-6d8729be5d95:3903172:9)
    14.  
     
  3. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Where did you download from? The latest published version is not in DLL form. It also doesn't use Reflection.Emit for AOT platforms like WebGL. The stack trace youre showing is using Emit. Did you purchase through asset store or fastspring? If it was fastspring, can you email me with the email address used for purchase so i can make sure the license is giving you the correct download?
     
  4. realshobu

    realshobu

    Joined:
    Nov 8, 2012
    Posts:
    4
    I got a crash on ios.
    My code is so simple, so I can't believe it makes error. Maybe I made other problems..

    Please check following code and logs.

    Unity 5.3.4p6
    JsonDotNet 1.5.0

    Code (CSharp):
    1. public class Tutoral
    2. {
    3.     public HashSet<int> completed;
    4. }
    5.  
    6. public void TouchToStart()
    7. {
    8.     Tutoral tutorial = new Tutoral() {
    9.         completed = new HashSet<int>(),
    10.     };
    11.     object data = tutorial;
    12.     string json = JsonConvert.SerializeObject( data );
    13.     Debug.Log( json );
    14. }

    Code (CSharp):
    1. ExecutionEngineException: Attempting to call method 'Newtonsoft.Json.Utilities.CollectionWrapper`1[[System.Int32, mscorlib, Version=2.0.5.0, Culture=, PublicKeyToken=7cee85d2bec45492e]]::.ctor' for which no ahead of time (AOT) code was generated.
    2.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    3.   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    4.   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    5.   at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory+<CreateMethodCall>c__AnonStoreyB7`1[T].<>m__75 (.T o, System.Object[] a) [0x00000] in <filename unknown>:0
    6.   at Newtonsoft.Json.Utilities.MethodCall`2[T,TResult].Invoke (.T target, System.Object[] args) [0x00000] in <filename unknown>:0
    7.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    8.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty (Newtonsoft.Json.JsonWriter writer, System.Object memberValue, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0
    9.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    10.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    11.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
    12.   at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
    13.   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0
    14.   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <filename unknown>:0
    15.   at GM.IntroScene.TouchToStart () [0x00000] in <filename unknown>:0
    16.   at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <filename unknown>:0
    17.   at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    18.   at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    19.   at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
    20.   at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in <filename unknown>:0
    21.   at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (.T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <filename unknown>:0
    22.   at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in <filename unknown>:0
    23.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in <filename unknown>:0
    24.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <filename unknown>:0
    25. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    26.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    27.   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    28.   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    29.   at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory+<CreateMethodCall>c__AnonStoreyB7`1[T].<>m__75 (.T o, System.Object[] a) [0x00000] in <filename unknown>:0
    30.   at Newtonsoft.Json.Utilities.MethodCall`2[T,TResult].Invoke (.T target, System.Object[] args) [0x00000] in <filename unknown>:0
    31.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    32.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty (Newtonsoft.Json.JsonWriter writer, System.Object memberValue, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0
    33.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    34.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) [0x00000] in <filename unknown>:0
    35.   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
    36.   at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0
    37.   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0
    38.   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <filename unknown>:0
    39.   at GM.IntroScene.TouchToStart () [0x00000] in <filename unknown>:0
    40.   at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <filename unknown>:0
    41.   at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    42.   at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    43.   at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
    44.   at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in <filename unknown>:0
    45.   at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (.T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <filename unknown>:0
    46.   at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in <filename unknown>:0
    47.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, Boolean pressed, Boolean released) [0x00000] in <filename unknown>:0
    48.   at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <filename unknown>:0
    49. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    50. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    51. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    That's Unity's crazy aggressive stripping. It stripped the default constructor off of CollectionWrapper. You'll have to add it to link.xml. In my upcoming update this will be addressed with preserve attributes and an included link.xml file. If you're not sure how to set it up I can give you an example in the morning when I get to the office .
     
  6. realshobu

    realshobu

    Joined:
    Nov 8, 2012
    Posts:
    4
    Thank you for swift response!
    I'll waiting for your link.xml exmaple. :)
     
  7. mmortall

    mmortall

    Joined:
    Dec 28, 2010
    Posts:
    89
    Sorry I took this dll from my old project. It was as dll there. Then I try to download latest dll from your website. Yes I have Asset store license, I re download it and I now see it is not dll currently. I just think version in asset is one year old so it was probably outdated. Thanks for help
     
  8. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    It is one year old but it fully supports WebGL. If you want, send me an email dustin (at) parentelement.com and send me your invoice number. I'll send you an update that's compiled as a DLL, and can send you a beta of the new version if you'd like.
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Give this a try:

    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8" ?>
    3. <linker>
    4.   <assembly fullname="Assembly-CSharp">
    5.     <namespace fullname="Newtonsoft.Json.Utilities" preserve="all" />
    6.     <type fullname="Newtonsoft.Json.Utilities.CollectionWrapper`1" preserve="all" />
    7.   </assembly>
    8.   <assembly fullname="System">
    9.     <type fullname="System.ComponentModel.TypeConverter" preserve="all" />
    10.   </assembly>
    11. </linker>
    12.  
    Give that a try and see if it stops it from being stripped.
     
  10. ChristineZ

    ChristineZ

    Joined:
    May 22, 2016
    Posts:
    7
    Hi,
    How can I fix this? I use Unity 5.3.4f1 and Xcode 7.1 beta (7B75).
    I first got a MissingMethodException for TypeConvertor when I run the app in Xcode for iPhone6s. I then added a link.xml file in asset folder with
    <linker>
    <assemblyfullname="System">
    <typefullname="System.ComponentModel.TypeConverter"preserve="all"/>
    </assembly>
    </linker>

    It doesn't give me missingMethodException now. But I got

    NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(21) : Unsupported internal call for IL2CPP: DynamicMethod::create_dynamic_method - System.Reflection.Emit is not supported.

    at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0

    at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0

    at FitroomAPI+<DoPostData>c__Iterator5.MoveNext () [0x00000] in <filename unknown>:0


    (Filename: currently not available on il2cpp Line: -1)


     
  11. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    By using my asset. :) You appear to be using Json .NET, but either the official version or one that came from somewhere else. My asset does not use Reflection.Emit on iOS (or any AOT device profile).
     
    Tinjaw likes this.
  12. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Daily(-ish) Update:
    1. I've been continuing work on the 8.0.4 port. Here is what has been happening:
      Cloned the official GitHub repo - this allows me to run diffs and fairly quickly merge official bug fixes and changes into the Json .NET for Unity asset so I don't have to try to retrofit things way down the road. There are a couple of new xml changes that I need to put into my code base.
    2. Removed JsonSchema, references and JsonValidatingReader. While these still technically 'exist' in the current official Json .NET source, they have been marked as Obsolete since it has been moved to its own separate (and commercial) product. Using it would result in code warnings since it is Obsolete, and the official release of Json .NET will no longer have updates or bug fixes to it. Because of these I have removed it from the Unity port.
    3. Removed references to System.Data for 'most' platforms. It did not result in errors with those references present and it still functioned fine across platforms. Most likely Unity is stripping that code from the AOT builds which is why. Since it's not supported in most Unity platforms, I 'removed' (via compiler directive) it. I did, however, leave it in for Windows SDK 8.1 and UWP (with .NET Backend) final builds as you may add additional code that references it in your final application and it is available to those platforms. I also left in .NET 4 features for these platforms such as System.Numerics (BigInteger, etc).
    4. Added Preserve attributes to Json .NET classes to prevent them from being stripped since some of them are accessed dynamically via reflection, or as a result of reflected types as the Unity compiler cannot reliably determine that they are being used.
    5. Added link.xml file that prevents TypeConverter from being stripped.
    6. Updated the Json .NET Build. A single solution with multiple projects will be included as a zip file with the release. This allows you to debug more easily and/or create your own builds if you'd like. The code will be in a /Source folder. Inside of that folder is a /Newtonsoft.Json folder that contains the projects and source. There is also /LinkXML and /Artifacts folders inside of Source. When the solution is built, the DLLs automatically build to /Source/Artifacts/{BuildConfig}/Assemblies/{Platform}, where {BuildConfig} is either Debug or Release, depending on the mode you have set, and {Platform} is AOT, Standalone, Win81 or Windows10. The AOT folder contains the DLL that works across AOT platforms (including all IL2CPP builds). Standalone contains the Editor assembly as well as the Standalone (PC / Mac / Linux) build and acts as the Placeholder for the Win81 and Windows10 builds. The link.xml file is also copied from the /Source/LinkXML folder to the /Source/Artifacts/{BuildConfig}/ folder as a post-build step.
    7. Added a VectorConverter which handles Vector2, Vector3, and Vector4 automatically and integrated that as a default converter. These and additional converters I will be adding will automatically avoid Unity's Xbox One bugs where built in structs fail to deserialize properly. They should also improve performance of serializing and deserializing those types as the converter handles reading and writing the json and Reflection will no longer be used to create and populate or read from those types.
    Next Steps:
    I have a few people beta testing right now. I'll be putting a new build in their hands today. It contains all of the above changes. There are a few more changes that are still in the works:
    1. Add Matrix4x4Converter, ResolutionConverter, UriConverter and ColorConverter to the list of built in default converters. I have converters written for these, I just need to clean them up and test more thoroughly.
    2. Look into any additional Unity types that may need custom converters.
    3. Test against versions of Unity prior to 5.3.4 and 5.3.5.
    4. Create Documentation geared toward Unity users.
    5. Create new code samples and a better Example scene (no more test scene).
    6. Find out the proper mapping for Xbox One, PS4 and WiiU if possible. I can't map the DLLs for those platforms because I don't have the SDKs, however, if I use text serialization and look at the .meta files for the DLLs I can see the configurations. I want to see if I can map those platforms by hand and see if the settings are retained on export. This is a 'should have' for me as it might not be possible, but it will make it easier for developers on those platforms so they don't have to map the DLLs themselves.
    Points 4 and 5 above are hugely important to me. The current release has a Test scene that I use to test common scenarios but it doesn't do a good job of illustrating how to do some of the serialization. Most people also rely on the official documentation for Json .NET which will be more reliable now that I'm getting the profile upgraded, however it is very technical documentation and not a great "How-To".

    I want to include documentation that provides better step-by-steps, how-to's and is more "Unity Friendly" so it's geared toward Unity developers that may not have a deep C# / .NET Background. This also allows me to concentrate on things like pointing out the importance of caching JsonSerializerSettings if you're using custom settings so you're not reallocating every time you serialize / deserialize.
     
    Tinjaw likes this.
  13. ChristineZ

    ChristineZ

    Joined:
    May 22, 2016
    Posts:
    7
    Hi Dustin,

    To use your asset, how to change in my project? It's my first time using Unity3d and Xcode to work on a mobile app. Can you explain more? maybe step by step? Thank you!
     
  14. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I'm assuming you have an existing Newtonsoft.Json.dll somewhere in your project. Delete that and import my asset. It is a port so it works as a replacement. That's all you should need to do.
     
  15. ChristineZ

    ChristineZ

    Joined:
    May 22, 2016
    Posts:
    7
    Yes, I have a file called NewtonSoft.Json Import Settings, two files named NewtonSoft.Json, one file called NewtonSoft.Json.dII. So I just need to delete NewtonSoft.Json.dII ? And place the your asset in the same place?
     

    Attached Files:

  16. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I'm guessing those other files are the xml documentation and pdb, etc. Just delete all of the Newtonsoft.Json files.
     
  17. ChristineZ

    ChristineZ

    Joined:
    May 22, 2016
    Posts:
    7
    thank you so much! U r such a big help!
     
    Dustin-Horne likes this.
  18. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Youre very welcome. :)
     
  19. realshobu

    realshobu

    Joined:
    Nov 8, 2012
    Posts:
    4
    I've tried your link.xml but still not working, same errors.
    Please let me know some other solution or workarounds..
     
  20. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Ok, I'll take a deeper look at the stack trace, and I may have not formatted that link.xml correct. It is still a result of something getting stripped by Unity. If you could, shoot me an email dustin (at) parentelement.com. I can send you an updated Beta which should fix the issue.
     
  21. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Just an update on the above, I've provided @realshobu with the latest beta build and it is working perfectly.
     
  22. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Daily-ish Update:
    The additional JsonConverters have been written. By default I will be turning on the VectorConverter, Matrix4x4Converter and ColorConverter. The other converters are for less commonly used types so they will be available, just not used by default.

    I have been testing on previous Unity versions and so far so good. Beta testers so far have been reporting positive results and I have not yet hit any snags or bugs.

    I've tentatively decided not to include an "Example Scene" with this release. I've opted instead to concentrate on better documentation that demonstrates both the "whats" and the "whys". I have been working hard on documentation that hopefully leads the user down a clear path of setup, basic usage and more advanced concepts, complete with code samples.

    The documentation will be geared toward my 2.0 release so it will contain many features that will only be available in 2.0, however I will provide the documentation here on the forums as well since I think it will provide benefit to existing version users.
     
  23. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    <- chomping at the bits so to say :)
     
    Dustin-Horne likes this.
  24. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Getting close. I still have one open bug... it's a Unity bug but I'm trying to work around it. HashSet<T> fails to deserialize on any IL2CPP platform but works on every other platform. I'm trying to write a custom converter that will handle it.
     
  25. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    UPDATE
    I have completed a HashSet<T> converter which allows a HashSet to serialize and deserialize properly on IL2CPP. I will be submitting a bug to Unity this week as well on the issue as it only affects IL2CPP (and therefore the converter will only be turned on by default for IL2CPP builds).

    I have made a lot of progress on documentation. Once I have the documentation finished in the next couple of days I will publish the updated version to the asset store.
     
    Tinjaw likes this.
  26. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    UPDATE
    Hopefully this is my next to last 2.0 News update! I've completed the first go-around for documentation and I'm pretty happy with it. It's 26 pages of explanation and code samples and aimed at Unity developers. I've also finished fixing all known bugs and getting my converters written.

    I am in the process of creating my projects now. Publishing to the store can be a royal pain. I want to support Unity 5.0 and up so to do that I have to publish from Unity 5. But I also have to publish from Unity 5.2 to include UWP support and support Unity 5.2 users... and from Unity 5.3 to support IL2CPP with UWP. So in essense I have to create three projects and publish three times to catch the full range of users and Unity versions I want to support.

    I'll be submitting the update to the store tomorrow (it's 11:30pm for me now). With any luck we should see 2.0 hit the store within the next week!
     
    Tinjaw likes this.
  27. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Just as an FYI - I've decided I will still support Unity 4.x on the following platforms:

    iOS, Android, PC, Linux, Mac, Xbox 360, Xbox One, PS3, PS4 and WiiU. I currently will not be able to support Windows 8.x or above on Unity 4.x. It would require manual DLL switching by the user. This will also require the latest 4.7.2 as that is what I'll publish from.

    I'm testing now before I build out that package just to make sure it will work.

    UWP (Windows 10) and Windows 8.1 Universal as well as all IL2CPP enabled platforms will be supported on Unity 5.x.
     
  28. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Version 2.0 has been submitted to the asset store! It took a little longer than expected... because Unity keeps adding new platforms so I had to publish from multiple Unity versions to make sure I catch them all. For maximum compatibility I published from:

    4.7.2
    5.0.0
    5.1.0
    5.2.0
    5.3.0

    That way I was able to map each platform as it was added (such as Tizen and UWP / IL2CPP). I'm hoping the turnaround time will be fairly quick!
     
    Metastable, siliwangi and Tinjaw like this.
  29. yurykorzun

    yurykorzun

    Joined:
    Oct 29, 2015
    Posts:
    41
     
  30. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    It will be available as soon as the asset store team approves it. You can get it earlier if you email me your invoice number:

    dustin (at) parentelement.com
     
  31. _josh

    _josh

    Joined:
    Dec 18, 2014
    Posts:
    7
    hey dustin, I got the earlier build, but it's giving me a no namespace name error when I try to build to the apple tv. Here's the log if you want to see it:

    Code (csharp):
    1. error CS0246: The type or namespace name `Newtonsoft' could not be found. Are you missing a using directive or an assembly reference?
    I can build to ios and android fine, but there seems to be an issue with building to the apple tv.
     
  32. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Send me an email to dustin (at) parentelement.com with your invoice number and I'll send you the new release. The older version isn't mapped for AppleTV and you can do it manually but it's a bit messy. You'd be better off just moving to the version I just submitted to the asset store (pending review).
     
  33. _josh

    _josh

    Joined:
    Dec 18, 2014
    Posts:
    7
    I currently have the one you submitted to the asset store.
     
  34. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Ahh ok, send me a quick email, I don't recall which email address was yours. So, it appears that Apple TV must have it's own DLL mapping option. What Unity version was it added in? I don't have it in my list of Platforms when I map the DLLs.

    I'll have to get it added to the documentation for Platform Mapping. You'll need to navigate to /JsonDotNet/Assemblies/AOT and select the Newtonsoft.Json.dll file in that folder. In the inspector, find the AppleTV platform, select it and click Apply. That will fix your issue.
     
  35. _josh

    _josh

    Joined:
    Dec 18, 2014
    Posts:
    7
    Thank you. That seemed to work! :]
     
  36. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Looks like I missed that platform because it was added after 5.3.0. Once v2.0 is approved on the asset store I'll push out a 2.0.1 that adds a 5.3.5 push and includes the AppleTV platform mapping.
     
  37. _josh

    _josh

    Joined:
    Dec 18, 2014
    Posts:
    7
    awesome. Thanks for the fast replies and quick fixes!
     
    Dustin-Horne likes this.
  38. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    What a stellar turnaround time by the Asset Store team! Version 2.0 is now LIVE on the asset store! You can get it here:
    http://u3d.as/5q2

    Edit: FastSpring purchasers will have access very soon through your parentelement.com account. The original licensing system was built on major version access so I need to update existing license records to give you access.
     
    fantastisch_ and Tinjaw like this.
  39. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    hi dustin, great work on the documentation!

    I sent an email a bit ago and noticed the update to 2.0... unfortunately, the issue I emailed you about still seems to exist in this release related to SerializationBinder.

    All development was primarily done against iOS; however, when switching the project over to WSA Universal, I get this message when trying to build (it is strange that everything works in the editor though):

    error CS7069: Reference to type 'SerializationBinder' claims it is defined in 'mscorlib', but it could not be found

    I have a few custom binders that are needed to translate the deserialized classes from the server namespaces to the client that look similar to this:

    Code (CSharp):
    1. using Assets.Scripts.Models;
    2. using Newtonsoft.Json.Serialization;
    3. using System;
    4. using System.Collections.Generic;
    5.  
    6.  
    7. namespace Assets.Scripts.Utils
    8. {
    9.     class DbInfoSerializationBinder : DefaultSerializationBinder
    10.     {
    11.         public override Type BindToType(string assemblyName, string typeName)
    12.         {
    13.             switch (typeName)
    14.             {
    15.                 case "SERVER.Models.DbInfo": return typeof(DbInfo);
    16.                 case "System.Collections.Generic.List`1[[SERVER.Models.DbInfo, SERVER]]": return typeof(List<DbInfo>);
    17.                 case "System.Collections.Generic.HashSet`1[[SERVER.Models.DbInfo, SERVER]]": return typeof(List<DbInfo>);
    18.  
    19.                 default:
    20.                     return base.BindToType(assemblyName, typeName);
    21.             }
    22.         }
    23.     }
    24. }

    Everything works great in the editor and even on iOS... I just can't build to Universal 10 (windows 10).. which is bad news.

    any ideas?

    [FIXED] (sorta?)
    ok, seems I needed to switch the project over to use IL2CPP instead of the .NET for the scripting backend... >.<

    can now start testing Universal 10 :)

    ugh.. c++ everywhere now..

    is there anyway to get this working with .NET for scripting backend? :(
     
    Last edited: Jun 19, 2016
  40. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I'll certainly take a look. It's possibly something wonky is going on with Unitys reference rewriter when it wants to use the other dll. Do you get this error during the build from unity or do you get it in visual studio after Unity has built the UWP project?
     
  41. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    this happens during the build from Unity when the scripting backend is set to .NET
     
  42. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Does it build fine without your custom serialization binder?
     
  43. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    actually.. nope.

    thought I was missing something, but I do have the scripting backend (at least I believe) installed..

    remarking anything releated to SerializationBinder starts throwing all kinds of other errors on my other classes like:

    error CS1061: 'StreamWriter' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'StreamWriter' could be found (are you missing a using directive or an assembly reference?)

    strange that builds for IL2CPP are working ok... I must have a botch Unity install or something is missing related to .NET.. not sure what though
     
    Last edited: Jun 19, 2016
  44. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Or your dll mappings are hosed somehow. Can you make sure that the assemblies/Windows dll is mapped to "Any SDK" and ".NET Backend" and has the Standalone picked as the placeholder? Also make sure the do not process box is not checked. It looks to me like the bindings are acting wonky.
     
  45. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I'll do that and check my installed SDK version..
     
  46. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I just checked and I'm not able to create a simple Universal app in Visual Studio 2015 update 1... so I'm thinking something is really wrong with my SDK installation for Universal apps.

    Let me see if I can get that fixed first.. they all may have nothing at all to do with the SerializationBinder.. :(
     
  47. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Yeah. I built and tested against Update 2 and Update 3 RC. I don't recommend updating Visual Studio to Update 3 until it's RTM... the RC of Visual Studio 2015 Update 3 seriously hosed my install so badly that I had to reinstall my OS.
     
  48. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    ok, of much-to-do.. I was able to get the SDK installed for Update 2 (10.0.10586.212 Windows 10 SDK), I'm able to create a simple Universal App now in Visual Studio.

    I did a test with Unity, created a blank project/scene.. exported to Universal 10 / XAML.. exported fine (nothing in it really).

    Unfortunately, I'm still getting the same SerializationBinder error on the other test project.

    I'll zip it up and email it to you...
     
  49. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Got it. I'll fire it up when I get to the office and see if it will run for me. My guess is that it will. What version of Unity are you using again? 5.3.5 correct?
     
  50. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    HEADS UP! In less than 1 hour, JSON .NET for Unity will be featured in the next 24-Hour Sale! We're so excited as this is our first 24-hour sale!