Robin
Robin

Reputation: 451

MissingMethodException in JSON.Net in Unity3D webplayer

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 

Upvotes: 0

Views: 972

Answers (2)

Jaime Mar&#237;n
Jaime Mar&#237;n

Reputation: 598

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);

Upvotes: 0

Robin
Robin

Reputation: 451

Found another similar problem, seems to be Unity3D screwup again

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

Upvotes: 1

Related Questions