title: Json.net deserializing dictionary containing dictionary with value of dataTable
body: <p>I am fairly new to programming (outside of a classroom environment).</p>
  
  <p>I'm working on an application that has plugins. Each plugin packs/unpacks it's state (as a dictionary) and sends itself to be added to a dictionary containing all packed states. I'm using Json.Net to serialize/deserialize and pass off each plugin to it's own class to be packed/unpacked depending on if the project is being saved or opened.</p>
  
  <p>The problem I'm having is when my first plugin gets its dictionary version of it's packed state to unpack, and I start going through the repopulating of each property, the first property (first item in the dictionary) is a DataTable. I'm getting an error saying: </p>
  
  <pre><code>Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to 
  type 'System.Data.DataTable'.
  </code></pre>
  
  <p>Here is my code for serializing. </p>
  
  <pre><code>IDictionary&lt;string, IDictionary&lt;string, object&gt;&gt; pluginStates = 
               new Dictionary&lt;string, IDictionary&lt;string, object&gt;&gt;();
  signaller.RaiseSaveRequest(pluginStates); //gets all of the plugins' packedState
  
  JsonSerializer serializer = new JsonSerializer();
  serializer.ObjectCreationHandling = ObjectCreationHandling.Replace; 
  serializer.TypeNameHandling = TypeNameHandling.All; 
  
  using (StreamWriter sw = new StreamWriter(strPathName))
  using (JsonWriter writer = new JsonTextWriter(sw))
  {
      serializer.Serialize(writer, pluginStates);
  }
  </code></pre>
  
  <p>and deserializing.</p>
  
  <pre><code> IDictionary&lt;string, IDictionary&lt;string, object&gt;&gt; pluginStates = 
             new Dictionary&lt;string, IDictionary&lt;string, object&gt;&gt;();
  
   JsonSerializer serializer = new JsonSerializer();
   serializer.ObjectCreationHandling = ObjectCreationHandling.Replace; 
   serializer.TypeNameHandling = TypeNameHandling.All; 
  
   StreamReader sr = new StreamReader(fullName);
   JsonTextReader reader = new JsonTextReader(sr);
   string json = sr.ReadToEnd();
   pluginStates = serializer.Deserialize&lt;IDictionary&lt;string, IDictionary&lt;string, Object&gt;&gt;&gt;(reader);
   pluginStates = JsonConvert.DeserializeObject&lt;IDictionary&lt;string, IDictionary&lt;string, Object&gt;&gt;&gt;(json);
   sr.Close();
   reader.Close();
  
   signaller.UnpackProjectState(pluginStates);
  </code></pre>
  
  <p>I've tried looking at the documentation on NewtonSoft.Json, but I barely understand it and how to make it work in my code. I'm thinking I need to do something with the Converters or Parsing once the plugin gets its packed state to unpack. When it was packed up, the plugin's 1st dictionary entry was saved as DataTable. Then, when in the Unpack, it's the actual dataTable in the value with the : separators. </p>
  
  <p>I would provide screen shots, but I haven't figured out how to do that. Any ideas what I'm missing?? 
  THANKS!</p>