Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3108

Deserialization throws No matching creator found exception

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.3, 2.10.4
    • Component/s: BSON
    • None
    • Environment:
      Windows 10

      When reading the data using C# driver 2.10.4, below exception is thrown if document has not all the attributes,

      "An error occurred while deserializing the property <property name> of class <clas name>: No matching creator found."

      When using the driver version 2.10.1, we do not see the issue

      Mongo DB document:

      {
         "_id":"23456",
         "type":"address",
         "attributes":{
            "name":"San",
            "address":[
               {
                  "name":"address1",
                  "street":"1430 Del santra, SA",
                  "city":"NY"
               },
               {
                  "name":"address2",
                  "city":"NY"
               }
            ]
         }
      }
      

      Sample program to reproduce:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      MongoUrl conString = new MongoUrl("mongodb://localhost:27017/");
      
      IMongoClient dbConnect = new MongoClient(conString);
      IMongoDatabase _dbMongo = dbConnect.GetDatabase("ApplicationDB");
      
      ConventionPack _conventions = new ConventionPack();
      _conventions.Add(new LowerCaseElementNameConvention());
      ConventionRegistry.Register("lowercaseconvention", _conventions, t => true);
      _conventions.Add(new IgnoreExtraElementsConvention(true));
      ConventionRegistry.Register("IgnoreExtraElements", _conventions, t => true);
      
      try
      {
      	var result = Task.Run( () => _dbMongo.GetCollection<AddressDetails>("simplecollection").Find(x => x.Type == "address" && x.Attributes.Name == "San").FirstOrDefaultAsync());
      	result.Wait();
      }
      catch (MongoException ex)
      {
      	Console.WriteLine($"{ex.Message}");
      }
      
      public class AddressDetails
      {
      	public string Id { get; set; }
      	public Attributes Attributes { get; private set; }
      	public string Type { get; private set; }
      
      public AddressDetails(string id, Attributes attributes, string type)
      {
      	Id = id;
      	Attributes = attributes;
      	Type = type;
      }
      
      public class Attributes
      {
      	public string Name { get; private set; }
      	public List<Address> Address { get; private set; }
      	public Attributes(string name, List<Address> address)
      	{
      		Name = name;
      		Address = address;
      	}
      }
      
      public class Address
      {
      	public string Name { get; private set; }
      	public string Street { get; private set; }
      	public string City { get; private set; }
      	public Address(string name, string street, string city)
      	{
      		Name = name;
      		Street = street;
      		City = city;
      	}
      }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            vargese.antony@gmail.com vargese antony
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: