title: DataContractJsonSerializer exception
body: <p>I am getting this error when using my class.</p>
  
  <h1>Error</h1>
  
  <blockquote>
    <p>Expecting element 'root' from namespace ''.. Encountered 'None' with
    name '', namespace</p>
  </blockquote>
  
  <h1>My Class</h1>
  
  <pre class="lang-cs prettyprint-override"><code>[DataContract]
  public class EntryData
  {
      [DataMember]
      public string EntryId { get; set; }
  
      [DataMember]
      public string EmailAddress { get; set; }
  
      [DataMember]
      public string StatusCode { get; set; }
  
      [DataMember]
      public string TotalVoteCount { get; set; }
  
      public static T Deserialise&lt;T&gt;(string json)
      {
          var obj = Activator.CreateInstance&lt;T&gt;();
          using (var memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(json)))
          {
              memoryStream.Position = 0;
              var serializer = new DataContractJsonSerializer(obj.GetType());
              obj = (T)serializer.ReadObject(memoryStream); // getting exception here                    
              return obj;
          }
      }
  }
  </code></pre>
  
  <h1>USAGE</h1>
  
  <pre class="lang-cs prettyprint-override"><code>string responseJson = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();
  var results = EntryData.Deserialise&lt;EntryData&gt;(response)
  </code></pre>
  
  <p>I have seen online that it has to do with the <code>memoryStream position</code> BUT as you can see i am setting it to the beginning.</p>
  
  <p>Please help.</p>
  
  <h1>Json going to handler</h1>
  
  <p>I don't set StatusCode or TotalVoteCount when passing JSON in. I don't think this is the problem though.</p>
  
  <pre><code>{
      "EntryId":"43",
      "EmailAddress":"test@email.com"
  }
  </code></pre>
  
  <h1>ANSWER</h1>
  
  <p>Instead of using Deserialize method in my class I am using now this.</p>
  
  <pre class="lang-cs prettyprint-override"><code>//commented out this code.        
  string responseJson = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();
  var results = EntryData.Deserialise&lt;EntryData&gt;(response)
  
  // this is the way to go using JavaScriptSerializer   
  var serializer = new JavaScriptSerializer();
  var results = serializer.Deserialize&lt;EntryData&gt;(response);
  </code></pre>