[CSHARP-1468] Unable to determine the serialization information for c => Convert(c).Id Created: 02/Nov/15  Updated: 04/Apr/16  Resolved: 04/Nov/15

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.1
Fix Version/s: 2.1.1

Type: Bug Priority: Major - P3
Reporter: Frédérik Charest Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-1463 OrderBy DateTime Closed

 Description   

Since we went from version 2.0.1 to 2.1.0 we get this error: Unable to determine the serialization information for c => Convert(c).Id

Here's the exception:

System.AggregateException : One or more errors occurred.
  ----> System.InvalidOperationException : Unable to determine the serialization information for c => Convert(c).Id.
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at RC.RcGraph.Infrastructure.SmokeTests.NewsStories.NewsStoryRepositoryTests.GetByIds() in NewsStoryRepositoryTests.cs: line 137
--InvalidOperationException
   at MongoDB.Driver.ExpressionFieldDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Driver.SingleItemAsArrayOperatorFilterDefinition`2.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Driver.MongoCollectionImpl`1.FindAsync(FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
   at MongoDB.Driver.IAsyncCursorSourceExtensions.<ToListAsync>d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at RC.RcGraph.Infrastructure.Util.MongoBaseContentRepository`1.<GetByIdsAsync>d__c.MoveNext() in MongoBaseContentRepository.cs: line 68

Here's the object structure:

public interface IContent {
  int Id { get; }
}
 
public class News : IContent {
  public int Id { get; private set; }
}
 
public abstract BaseRepository<T> where T : IContent {
  public async Task<List<T>> GetByIdsAsync(IEnumerable<int> ids) {
    var filter = Builders<T>.Filter.In(c => c.Id, ids);
    return await GetCollection()
                      .Find(filter)
                      .ToListAsync();
  }
}

Here are the conventions:

BsonClassMap.RegisterClassMap<News>(cm => { cm.AutoMap() });



 Comments   
Comment by Sandra Greenhalgh [ 12/Nov/15 ]

Awesome, thanks

Comment by Craig Wilson [ 12/Nov/15 ]

Hi saan800, we released 2.1.1 yesterday.

Comment by Sandra Greenhalgh [ 10/Nov/15 ]

I'm also getting this issue. Is there an ETA for a new nuget package for version 2.1.1? Or a prerelease pacakge?

Comment by Frédérik Charest [ 04/Nov/15 ]

Alright, this is also working on my end!

Comment by Githook User [ 04/Nov/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1468: Fix conversion issue to base class.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c177452fce127e7c372ba4c7ed667eb5ed24f496

Comment by Donatas Tutinas [ 04/Nov/15 ]

We've been also having this issue in our asp.net 5 environment. Bug only started to appear after upgrading to asp beta8 version for some reason.

Anyway using the new Craig's build, we do not have this issue anymore, so looks as this is fixed thanks.

Comment by Craig Wilson [ 03/Nov/15 ]

Hi Frederik,

I've pushed a fix to our 2.1 branch. One of the other developers here wasn't able to reproduce the issue at all, while I was. Would you mind ensuring that this has fixed your issue? We have a build nuget feed at myget that has this build in it. Here is a direct link to the nuget package: https://www.myget.org/F/mongodb/api/v2/package/MongoDB.Driver-Build/2.1.1-build-0003.

Thanks,
Craig

Comment by Githook User [ 03/Nov/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1468: Fix conversion issue to base class.
Branch: v2.1.x
https://github.com/mongodb/mongo-csharp-driver/commit/91f4c132f8854d50222e222b541be88228f347bf

Comment by Craig Wilson [ 02/Nov/15 ]

Frederik,

Thanks for the report. I can reproduce this. It has to do with the generic type constraint in your base repository. I'll start working on a fix.

Craig

Comment by Frédérik Charest [ 02/Nov/15 ]

Mmm, I wanted to format the code in monospace, but it didn't work and now I can't edit it :/

Generated at Wed Feb 07 21:39:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.