[CSHARP-1190] Expression Trees with an upcasted conversion lose original serializer Created: 06/Mar/15  Updated: 02/Apr/15  Resolved: 06/Mar/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.0

Type: Bug Priority: Major - P3
Reporter: Craig Wilson Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The below test should pass, but doesn't because it treats the predicate as an IEntity, not as a MyEntity.

[TestFixture]
public class InterfaceSample
{
    [Test]
    public async Task Test()
    {
        var subject = DriverTestConfiguration.Client.GetDatabase("test").GetCollection<MyEntity>("test");
        await subject.DeleteManyAsync("{}");
        await subject.InsertOneAsync(new MyEntity { Id = 3, Type = "awesome" });
 
        var entity = await Find(subject, 3);
    }
 
    private Task<T> Find<T>(IMongoCollection<T> collection, int id) where T : IEntity
    {
        return collection.Find(x => x.Id == id).FirstOrDefaultAsync();
    }
}
 
public interface IEntity
{
    int Id { get; set; }
}
 
public class MyEntity : IEntity
{
    public int Id { get; set; }
 
    public string Type { get; set; }
}



 Comments   
Comment by Githook User [ 06/Mar/15 ]

Author:

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

Message: CSHARP-1190: fixed issue with generic constraint causing improper serializer lookup in the SerializationInfoBinder.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3e8cf28e1dccb24de7ef7e5820ef9ea4a16dc6b7

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