Note that there are some explanatory texts on larger screens.

plurals
  1. POSystem.TypeLoadException when I try to convert JArray to an object in a thread
    primarykey
    data
    text
    <p>I have a C# code that converts a JArray object <strong>jsonArray</strong> (JSON.Net) to a list of objects <strong>jsonList</strong> (List&lt; MyClass >):</p> <pre><code>List&lt;MyClass&gt; jsonList = jsonArray.ToObject&lt;List&lt;MyClass&gt;&gt; (); </code></pre> <p>The code above works fine when I run it on the main thread, but if I put the same code inside a different thread, like this:</p> <pre><code>Thread t = new Thread(delegate() { List&lt;MyClass&gt; jsonList = jsonArray.ToObject&lt;List&lt;MyClass&gt;&gt; (); }); t.Start(); </code></pre> <p>I get the following error message: "System.TypeLoadException has been thrown. A type load exception has occurred".</p> <p>Does anybody have any idea why this is happening? The full stack trace is below. Thanks in advance!</p> <blockquote> <p>System.TypeLoadException: A type load exception has occurred. at Newtonsoft.Json.Utilities.ThreadSafeStore<code>2[System.Type,System.Type].AddValue (System.Type key) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Utilities.ThreadSafeStore</code>2[System.Type,System.Type].Get (System.Type key) [0x00000] in :0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociatedMetadataType (System.Type 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 at Newtonsoft.Json.Utilities.ThreadSafeStore<code>2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].AddValue (ICustomAttributeProvider key) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Utilities.ThreadSafeStore</code>2[System.Reflection.ICustomAttributeProvider,Newtonsoft.Json.JsonContainerAttribute].Get (ICustomAttributeProvider key) [0x00000] in :0 at Newtonsoft.Json.Serialization.CachedAttributeGetter<code>1[Newtonsoft.Json.JsonContainerAttribute].GetAttribute (ICustomAttributeProvider type) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonContainerAttribute (System.Type type) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonObjectAttribute (System.Type type) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe (System.Type type) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType, Boolean isNullable) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Linq.JToken.ToObject (System.Type objectType) [0x00000] in &lt;filename unknown&gt;:0 at Newtonsoft.Json.Linq.JToken.ToObject[List</code>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/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</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload