JArray オブジェクトjsonArray (JSON.Net) をオブジェクトjsonList (List< MyClass >)のリストに変換する C# コードがあります。
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 ] in :0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (System.Type type) [0x00000] in :0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[JsonContainerAttribute] (ICustomAttributeProvider attributeProvider) [0x00000] in :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 キー) [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] in /Users/vegidio/Documents/Dev/Xamarin/GuiaTV/GuiaTV/Controllers/AgoraController.cs:24 at GuiaTV.AgoraScreen.m__2 () [0x0000d] in /Users/vegidio/Documents/Dev/Xamarin /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Thread.cs:697 の System.Threading.Thread.StartInternal () [0x0001d] で /GuiaTV/GuiaTV/Views/AgoraScreen.cs:43