title: MongoDB C# Driver Exception Message=Element '' does not match any field or property of class
body: <p>The problem was a <strong>typo</strong> with <code>RequiresAuthenticationFlag</code> versus <code>RequiresAuthentication</code>. </p>
  
  <p>I do not understand why the driver did <strong>not</strong> include the name of the variable inside the exception.</p>
  
  <p>So if possible I would slightly change the question into. <strong>Why does the driver not include the element name inside the exception?</strong></p>
  
  <p>When I remove some characters of the DB variable's name, it does not throw a meaningful exception.
  DB Name: <code>Requires</code>
  Class Name: <code>RequiresAuthentication</code></p>
  
  <p>Exception does not contain correct field name.</p>
  
  <p>When it is the other way around. It does contain a full name!</p>
  
  <p>(Class contains <code>Requires</code> and DB <code>RequiresAuthentication</code>)</p>
  
  <p><strong>I think that must be a bug in the exception handling?</strong></p>
  
  <hr>
  
  <p>MongoDB C# Driver Exception: </p>
  
  <pre><code>Message=Element '' does not match any field or property of class 
  </code></pre>
  
  <p>This is my repository method that causes the exception:</p>
  
  <pre><code>public List&lt;TEntity&gt; GetAll()
  {
      return this.GetAllAsync().GetAwaiter().GetResult();
  }
  </code></pre>
  
  <p>I Checked the document and it does not seem to contain any empty element.</p>
  
  <p>This is the full exeption "Message"</p>
  
  <pre><code>{"An error occurred while deserializing the Smtp property of class 
  Example.Data.CustomerInstanceConfig: Element '' does not match any field or 
  property of class Example.Data.SmtpClientConfiguration."}
  </code></pre>
  
  <p>It does not make any sense for me since it actually talks about an '' (empty element)? So I assume something went wrong in the communication.</p>
  
  <p>Any suggestions how to proceed with debugging this message?</p>
  
  <p>JSON Structure (Copied from MongoChef Tool):</p>
  
  <pre><code>{ 
      "_id" : ObjectId("55b7899865fabbf5a962fae2"), 
      "SenderEmailAddress" : "abc", 
      "CustomerInstanceName" : "abc", 
      "EmailSignature" : null, 
      "PhoneNumber" : "+123", 
      "PasswordCapitalLetters" : false, 
      "PasswordNumbers" : false, 
      "PasswordMinLength" : NumberInt(4), 
      "PasswordSymbols" : false, 
      "ConfigMaxAgeInvitationCode" : NumberInt(30), 
      "ConfigMaxAgeForgotPasswordCode" : NumberInt(1), 
      "Smtp" : {
          "Host" : "abc", 
          "Port" : NumberInt(25), 
          "Password" : "test", 
          "RequiresAuthentication" : false, 
          "test" : "test"
      }
  }
  </code></pre>
  
  <p>I am working in a Windows Environment: Just in case if that matters in terms of any known bugs for the MongoDB driver or server.</p>
  
  <p>The Property Smtp the driver is talking about is a separate class.</p>
  
  <pre><code>public class CustomerInstanceConfig : EntityBase
  {
      public CustomerInstanceConfig()
      {
          PasswordMinLength = 4;
      }
      public string SenderEmailAddress { get; set; }
      public string CustomerInstanceName { get; set; }
      public string EmailSignature { get; set; }
      public string PhoneNumber { get; set; }
      public bool PasswordCapitalLetters { get; set; }
      public bool PasswordNumbers { get; set; }
      public int PasswordMinLength { get; set; }
      public bool PasswordSymbols { get; set; }
      public int ConfigMaxAgeForgotPasswordCode { get; set; }
      public int ConfigMaxAgeInvitationCode { get; set; }
  
      public SmtpClientConfiguration Smtp { get; set; }
  </code></pre>
  
  <p>[...]</p>
  
  <pre><code>public class SmtpClientConfiguration
  {
      public string Host { get; set; }
      public int Port { get; set; }
  
      public string Username { get; set; }
      public string Password { get; set; }
  
      public bool RequiresAuthenticationFlag { get; set; }
  }
  </code></pre>