title: Deserialize json with C# .NET Core
body: <p>Im trying to deserialize data that Ive got over POST in JSON format but having some problem.</p>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>SerializationException: Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''.
    System.Runtime.Serialization.XmlObjectSerializerReadContext.HandleMemberNotFound(XmlReaderDelegator xmlReader, ExtensionDataObject extensionData, int memberIndex)</p>
  </blockquote>
  
  <p>Controller where the serialization is happening:</p>
  
  <pre><code>    public String RequestToken(string userData)
      {
              Contract.Ensures(Contract.Result&lt;string&gt;() != null);
              UserModel deserializedUser = new UserModel();
              MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(userData));
              ms.Position = 0;
              DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType());
              deserializedUser = ser.ReadObject(ms) as UserModel;
      }
  </code></pre>
  
  <p>UserModel that is used as a contract:</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  using MongoDB.Bson;
  using MongoDB.Bson.Serialization.Attributes;
  
  namespace WishareIntegrationApi.Entities
  {
      [DataContract]
      public class UserModel
      {
          [BsonId]
          [BsonRepresentation(BsonType.String)]
          [DataMember]
          public ObjectId _id { get; set; }
          [DataMember]
          public string displayName { get; set; }
          [DataMember]
          public string photoURL { get; set; }
          [DataMember]
          public string email { get; set; }
          [DataMember]
          public int registeredAt { get; set; }
      }
  }
  </code></pre>
  
  <p>And an example JSON i'm sending over post:</p>
  
  <pre><code>{"_id":"8kmXH1fzSrVS8PqNLMwyhRH4hBw1","displayName":"Michal Takáč","photoURL":"https://lh3.googleusercontent.com/-xa5oE48RffQ/AAAAAAAAAAI/AAAAAAAACDE/OLrtV5-VIvw/photo.jpg","email":"email.takac@gmail.com"}
  </code></pre>