Serialization error in MongoDb Dictionary property using RegEx

643 views
Skip to first unread message

danyolgiax

unread,
Apr 10, 2014, 4:02:23 AM4/10/14
to mongodb...@googlegroups.com
Im trying to write the code filters a collection of documents with a property of type Dictionary<string,object>.

Code is the following:

var query = myCollection.AsQueryable();

var regex = new Regex("^Foo");

query = query.Where(x => regex.IsMatch(x.User["FullName"].ToString())); <--- Error here
running this code I get this error:

Unable to determine the serialization information for the expression: x.User.get_Item("FullName").ToString()
Document is declared in this way:

public class MyClass
{
    [BsonId]
    public ObjectId _id { get; set; }

    [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] //Tryied also Dynamic, Document, ArrayOfArray
    public Dictionary<string, object> User { get; set; }
}

Debugging Driver source code I found something strange. In BsonSerializationInfoFinder class, node.Method.Name must be ElementAt or get_Item while in this case it is ToString and it returns null raising the exception!

protected override BsonSerializationInfo VisitMethodCall(MethodCallExpression node)
    {
        switch (node.Method.Name)
        {
            case "ElementAt":
                return VisitElementAt(node);
            case "get_Item":
                return VisitGetItem(node);
        }

        return null;
    }    
Is this a driver bug?

danyolgiax

unread,
Apr 10, 2014, 4:17:53 AM4/10/14
to mongodb...@googlegroups.com
I think I found the problem:

Reply all
Reply to author
Forward
0 new messages