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

FormatException when using AutoMapper.ProjectTo

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Linq
    • None

       

      var mapperConfiguration = new MapperConfiguration(config =>
      {
          config.CreateMap<Post, PostDto>();
          config.CreateMap<Post.EmbeddedCategory, PostDto.CategoryDto>();
          config.CreateMap<Post.EmbeddedComment, PostDto.CommentDto>();
      });
      var mapper = mapperConfiguration.CreateMapper();
      var result = postCollection
           .AsQueryable()
           .ProjectTo<PostDto>(mapper.ConfigurationProvider)
           .ToList();
      
       Message: System.FormatException : An error occurred while deserializing the Category property of class MongoDb.Bugs.PostDto: Element 'Id' does not match any field or property of class MongoDb.Bugs.PostDto+CategoryDto. ---- System.FormatException : Element 'Id' does not match any field or property of class MongoDb.Bugs.PostDto+CategoryDto. Stack Trace: MongoQueryProviderImpl`1.Execute(Expression expression) MongoQueryableImpl`2.GetEnumerator() List`1.ctor(IEnumerable`1 collection) Enumerable.ToList[TSource](IEnumerable`1 source) Tests.AutoMapper_ProjectTo() line 41 ----- Inner Stack Trace ----- BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context) BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context) BsonClassMapSerializer`1.DeserializeMemberValue(BsonDeserializationContext context, BsonMemberMap memberMap)
      

       

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            mj.ebrahimi72@gmail.com Mohamad Javad Ebrahimi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: