我有一個JArray對象jsonArray(JSON.Net)轉換爲對象jsonList列表的C#代碼(列表< MyClass的>) :System.TypeLoadException當我嘗試JArray轉換爲對象的線程
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>>();
,當我在主線程上運行它上面的代碼工作正常,但如果我把相同的代碼不同的線程裏面,像這樣:
Thread t = new Thread(delegate() {
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>>();
});
t.Start();
我得到了以下電子錯誤信息:「System.TypeLoadException已被拋出。 ?A型負載異常發生,」
有誰知道爲什麼發生這種情況的任何想法完整的堆棧跟蹤低於預先感謝
System.TypeLoadException:!發生A型負載例外。在 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的]。獲得 (System.Type的鍵)的[0x00000]中:0在 Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (系統。類型類型)[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 key)[0x00000] in:0 at 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] in:0 at GuiaTV.AgoraController。 GetJSON()[0x00015] /Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Controllers/AgoraController.cs:24 at GuiaTV.AgoraScreen.m__2()[0x0000d] in /Users/vegidio/Documents /開發/ Xamarin/GuiaTV/GuiaTV/Views/AgoraScreen.cs:43 at System.Threading.Thread.StartInternal()[0x0001d] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs: 697
您的問題可能與此問題有關:http:// stackoverflow。com/questions/10112533/monotouch-with-newtonsoft-not-working – 2013-02-24 03:51:59
非常感謝,幫助。顯然,有一個與MonoTouch配合使用的特定版本的JSON.Net。 – vegidio 2013-02-24 04:35:27