The problem was a typo with RequiresAuthenticationFlag
versus RequiresAuthentication
.
I do not understand why the driver did not include the name of the variable inside the exception.
So if possible I would slightly change the question into. Why does the driver not include the element name inside the exception?
When I remove some characters of the DB variable's name, it does not throw a meaningful exception.
DB Name: Requires
Class Name: RequiresAuthentication
Exception does not contain correct field name.
When it is the other way around. It does contain a full name!
(Class contains Requires
and DB RequiresAuthentication
)
I think that must be a bug in the exception handling?
MongoDB C# Driver Exception:
Message=Element '' does not match any field or property of class
This is my repository method that causes the exception:
public List<TEntity> GetAll()
{
return this.GetAllAsync().GetAwaiter().GetResult();
}
I Checked the document and it does not seem to contain any empty element.
This is the full exeption "Message"
{"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."}
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.
Any suggestions how to proceed with debugging this message?
JSON Structure (Copied from MongoChef Tool):
{
"_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"
}
}
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.
The Property Smtp the driver is talking about is a separate class.
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; }
[...]
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; }
}