У меня есть код C#, который преобразует объект JArray jsonArray (JSON.Net) в список объектов jsonList (List‹ MyClass >):
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
Приведенный выше код отлично работает, когда я запускаю его в основном потоке, но если я помещу тот же код в другой поток, например так:
Thread t = new Thread(delegate() {
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
});
t.Start();
Я получаю следующее сообщение об ошибке: «Было выброшено исключение System.TypeLoadException. Произошло исключение загрузки типа».
Кто-нибудь знает, почему это происходит? Полная трассировка стека приведена ниже. Заранее спасибо!
System.TypeLoadException: произошло исключение загрузки типа. в Newtonsoft.Json.Utilities.ThreadSafeStore
2[System.Type,System.Type].AddValue (System.Type key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Utilities.ThreadSafeStore
2[System.Type,System.Type].Get (ключ System.Type) [0x00000] в: 0 в Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (тип System.Type) [0x00000] в: 0 в Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (тип System.Type) [0x00000] в: 0 в Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (ICustomAttributeProvider attributeProvider) [0x00000] в: 0 в Newtonsoft.Json.Utilities.ThreadSafeStore2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].AddValue (ICustomAttributeProvider key) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Utilities.ThreadSafeStore
2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].Get (ключ ICustomAttributeProvider) [0x00000] в: 0 в Newtonsoft.Json.Serialization.CachedAttributeGetter1[Newtonsoft.Json.JsonContainerAttribute].GetAttribute (ICustomAttributeProvider type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonContainerAttribute (System.Type type) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonObjectAttribute (System.Type type) [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.GetContractSafe (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.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType, Boolean isNullable) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Linq.JToken.ToObject[List
1] () [0x00000] в: 0 в GuiaTV.AgoraController.GetJSON () [0x00015] в /Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Controllers/AgoraController.cs:24 в GuiaTV.AgoraScreen.m__2 () [0x0000d] в /Users/ vegidio/Документы /Dev/Xamarin/GuiaTV/GuiaTV/Views/AgoraScreen.cs:43 в System.Threading.Thread.StartInternal () [0x0001d] в /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread .cs:697