0

I'm serializing object using JSON.Net 5.0r6 on Unity3D, dotnet 2 version. I can run it fine in the Webplayer mode in Editor build, but when I deploy to Webplayer. I get a missing exception. I can get the same code to run fine on Android (without stripping) so it's not the code side.

MissingMethodException: Method not found: 'System.Collections.ObjectModel.KeyedCollection<System.String,Newtonsoft.Json.Serialization.JsonProperty>..ctor'.
  at Newtonsoft.Json.Serialization.JsonObjectContract..ctor (System.Type underlyingType) [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.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0 

  at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 

  at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 

  at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 

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

  at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
1
  • ive got some code that does raw byte array packing which is pretty clean if you want it? Commented Aug 26, 2013 at 15:56

2 Answers 2

1

Found another similar problem, seems to be Unity3D screwup again

http://forum.unity3d.com/threads/133505-webplayer-and-System-Collections-ObjectModel-KeyedCollection

Sign up to request clarification or add additional context in comments.

Comments

0

Unfortunately there is a problem with the use of KeyedCollection (originally in the mscorlib) that is implemented in JSON.Net.

The solution for me was to replace the whole implementation with LitJson.dll

The only two methods that actually I use from JSON.Net are

    //JSON.Net
    JsonConvert.DeserializeObject<YourClass>(jsonSring);
    JsonConvert.SerializeObject(yourObject);

and you could easily change them with

    //LitJson
    JsonMapper.ToObject<YourClass>(jsonSring);
    JsonMapper.ToJson(yourObject);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.