3

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; }
}
Matthias
  • 1,386
  • 3
  • 24
  • 59
  • Whats the structure of the objects you are trying to get? I'm not sure if this is the answer you are looking for: [link](http://stackoverflow.com/a/10834578/1990724) – Martin M Aug 12 '15 at 09:55
  • I just posted the JSON Structure of the MongoDB document I am trying to get. – Matthias Aug 12 '15 at 09:57
  • 1
    I think the link you posted is a bit outdated. The MongoDB driver evolved a lot during the last year. – Matthias Aug 12 '15 at 09:58
  • Please see my updated questions. I actually found the solution, but I am not happy with the provided exception text. Is there a way to improve this? – Matthias Aug 12 '15 at 12:02
  • I decided to make a post in the MongoDB's Jira too: https://jira.mongodb.org/browse/CDRIVER-806 – Matthias Aug 14 '15 at 09:29

0 Answers0