2013-02-24 44 views
1

我有一個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.ThreadSafeStore 2[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.CachedAttributeGetter 1[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

+1

您的問題可能與此問題有關:http:// stackoverflow。com/questions/10112533/monotouch-with-newtonsoft-not-working – 2013-02-24 03:51:59

+0

非常感謝,幫助。顯然,有一個與MonoTouch配合使用的特定版本的JSON.Net。 – vegidio 2013-02-24 04:35:27

回答

1

看來你正在開發一個基於觸摸的應用程序,因此你需要最新版本的NewtonSoft for Mono Touch.Get從here

如果你正在建設它爲現代UI其很容易跟隨運8模板或使用一個任務來啓動線程。

嘗試投入呵,catch,finally塊來獲得異常的詳細信息。

+0

謝謝。爲了在MonoTouch上工作,我不知道有一個特定的JSON.Net端口。 – vegidio 2013-02-24 04:38:46

+0

如果你喜歡答案,那麼你可以接受它。它可以支持你。任何關於問題的疑問你都可以提出問題,然後只有我們可以把我們的大腦和互聯網搜索技術得到答案。 – Sant14 2013-02-24 05:47:58

0

如果設置

List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>>(); 

和懸停該斷點來看看內部異常的斷點,它說什麼了?

我之所以這樣問是因爲TypeLoad異常或者拋出一個空或給你的內部異常的消息,可以幫助你比這個堆棧跟蹤多一點。

相關問題