title: System.Runtime.Serialization.SerializationException: Member 'ClassName' was not found
body: <p>What does this error mean exactly?</p>
  
  <pre><code>System.Runtime.Serialization.SerializationException: Member 'ClassName' was not found.
     at System.Runtime.Serialization.SerializationInfo.GetElement(String name, Type&amp; foundType)
     at System.Runtime.Serialization.SerializationInfo.GetString(String name)
     at System.Exception..ctor(SerializationInfo info, StreamingContext context)
     at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object , Object[] )
     at Newtonsoft.Json.Serialization.DefaultContractResolver.&lt;&gt;c__DisplayClass10.&lt;CreateISerializableContract&gt;b__f(Object[] args)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
     at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
     at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
     at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
     at System.Exception..ctor(SerializationInfo info, StreamingContext context)
     at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object , Object[] )
     at Newtonsoft.Json.Serialization.DefaultContractResolver.&lt;&gt;c__DisplayClass10.&lt;CreateISerializableContract&gt;b__f(Object[] args)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
     at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
     at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
     at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
     at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
     at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
  </code></pre>
  
  <p>Deserialization fails on a complex object with the above error.   Error is also too vague so cannot tell what is wrong here.</p>
  
  <p><strong>EDIT</strong>
  This is not a duplicate of what has been provided as suggestion.  As explained in the problem, the issue occurs only when I use the auto-property initializer.  </p>
  
  <pre><code>public PayCodeDto PayCode {get; set;} = PayCodeDto.Invalid;
  </code></pre>
  
  <p>PayCode class is simple as follows:</p>
  
  <pre><code>  public class PayCodeDto: IEquatable&lt;PayCodeDto&gt;
      {
          public static readonly PayCodeDto Invalid = new PayCodeDto("-1", "Invalid") { DictionaryId = -1 }; 
  
          public string Name { get; set; }
          public string Id { get; set; }
          public int DictionaryId {get;set;}
  
          public PayCodeDto()
          {
          }
  
          public PayCodeDto(string id, string name)
          {
              Id = id;
              Name = name;
          }
  
          public override bool IsValid()
          {
              if (string.IsNullOrWhiteSpace(Id) || string.IsNullOrWhiteSpace(Name))
                  return false;
  
              return !Equals(Invalid);
          }
  
          public bool Equals(PayCodeDto other)
          {
              if (ReferenceEquals(null, other)) return false;
              if (ReferenceEquals(this, other)) return true;
              return string.Equals(Name, other.Name) 
                  &amp;&amp; string.Equals(Id, other.Id)
                  &amp;&amp; DictionaryId == other.DictionaryId;
          }
  
          public override bool Equals(object obj)
          {
              if (ReferenceEquals(null, obj)) return false;
              if (ReferenceEquals(this, obj)) return true;
              if (obj.GetType() != this.GetType()) return false;
              return Equals((PayCodeDto) obj);
          }
  
          public override int GetHashCode()
          {
              unchecked
              {
                  var hashCode = DictionaryId.GetHashCode();
                  hashCode = (hashCode * 397) ^ (Id != null ? Id.GetHashCode() : 0);
                  hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
  
                  return hashCode;
              }
          }
  }
  </code></pre>
  
  <p>If I remove the initializer, error no longer occurs.  </p>