Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JObject -> HashSet Exception on IOS #8

Open
zpavlov opened this issue Jul 19, 2016 · 3 comments
Open

JObject -> HashSet Exception on IOS #8

zpavlov opened this issue Jul 19, 2016 · 3 comments

Comments

@zpavlov
Copy link

zpavlov commented Jul 19, 2016

As a side note, serializing to string and back works fine on iOS, it just appears to be ToObject.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public class JFail : MonoBehaviour {

    public class JsonFailure {
        public HashSet<string> foo;
        public JsonFailure() {
            foo = new HashSet<string>();
            foo.Add("HI THERE");
        }
    }
    void Start() {
        JsonFailure original = new JsonFailure();
        JObject jobject = JObject.FromObject(original);
        Debug.Log("JObject: " + jobject.ToString());
        Debug.Log (jobject["foo"].Type.ToString ());

        //Argument Non Null exception on IOS
        JsonFailure backFromJObject = jobject.ToObject<JsonFailure>();
        Debug.Log("---------------------DONE");
    }

}

In editor, this works as expected, but on IOS, the ToObject call exceptions with the following error
(apologies for lack of line number due to il2cpp)

ArgumentNullException: Argument cannot be null.
Parameter name: method
at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull (System.Object value, System.String parameterName) [0x00000] in :0
at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory.CreateParameterizedConstructor (System.Reflection.MethodBase method) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in :0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in :0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in :0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in :0
at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in :0
at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType) [0x00000] in :0
at JFail.Start () [0x00000] in :0

@veblush
Copy link
Contributor

veblush commented Jul 20, 2016

Oh I confirmed that it happened on my machine, too. I'll take a look at it 👍

@zpavlov
Copy link
Author

zpavlov commented Jul 20, 2016

thanks! We're currently working around this and another issue related to bools using jsonproperty attributes and onDeserialized/onSerialized properties to convert the data

@veblush
Copy link
Contributor

veblush commented Jul 21, 2016

Ok. I fixed this problem. Please install the latest release. (previous one is replaced) and put following code on anywhere in your executable code path.

Newtonsoft.Json.Utilities.AotHelper.EnsureList<string>();

This makes Unity3D take necessary classes for deserializing HashSet<string> in iOS executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants