ฉันมีรหัส 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 has been Thrown มีข้อผิดพลาดในการโหลดประเภทเกิดขึ้น"
ไม่มีใครมีความคิดว่าทำไมสิ่งนี้ถึงเกิดขึ้น? การติดตามสแต็กแบบเต็มอยู่ด้านล่าง ขอบคุณล่วงหน้า!
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] (ICustomAttributeProviderattributeProvider) [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/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Views/AgoraScreen.cs:43 ที่ System.Threading.Thread.StartInternal () [0x0001d] ใน /Developer/MonoTouch/Source/mono/mcs/class/corlib/System. การทำเกลียว/Thread.cs:697