Saya memiliki kode C# yang mengonversi objek JArray jsonArray (JSON.Net) menjadi daftar objek jsonList (Daftar‹ MyClass >):
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
Kode di atas berfungsi dengan baik ketika saya menjalankannya di thread utama, tetapi jika saya meletakkan kode yang sama di dalam thread yang berbeda, seperti ini:
Thread t = new Thread(delegate() {
List<MyClass> jsonList = jsonArray.ToObject<List<MyClass>> ();
});
t.Start();
Saya mendapatkan pesan kesalahan berikut: "System.TypeLoadException telah dilemparkan. Telah terjadi pengecualian pemuatan tipe".
Adakah yang tahu mengapa ini terjadi? Jejak tumpukan lengkap ada di bawah. Terima kasih sebelumnya!
System.TypeLoadException: Pengecualian pemuatan tipe telah terjadi. di 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].Dapatkan (kunci System.Type) [0x00000] di :0 di Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (tipe System.Type) [0x00000] di :0 di Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (tipe System.Type) [0x00000] di :0 di Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (ICustomAttributeProvider atributProvider) [0x00000] di : 0 di 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].Dapatkan (kunci ICustomAttributeProvider) [0x00000] di :0 di 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] di : 0 di GuiaTV.AgoraController.GetJSON () [0x00015] di /Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Controllers/AgoraController.cs:24 di GuiaTV.AgoraScreen.m__2 () [0x0000d] di /Users/ vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Views/AgoraScreen.cs:43 di System.Threading.Thread.StartInternal () [0x0001d] di /Developer/MonoTouch/Source/mono/mcs/class/corlib/System. Utas/Utas.cs:697