When you want to deserialize an object using an interface using this setup. It crashes with BsonSerializationException "No serializer found for type X". The way i have mongo setup is like this.
MongoRepository<TObject>
{
public MongoRepository(string serverUrl, string databaseName, MongoCredentials credentials)
public TObject Find(Expression<Func<TObject,bool>> predicate)
{ return _mongoCollection.AsQueryable().FirstOrDefault(predicate); }}
When TObject is an Interface type it crashes with BsonSerializationException. A fix that works pretty well on git commit 6a30fd35ea2d45b3aa8f2c7b176a24e90980f150 in the BsonSerializer.cs file line 589 in the LookupSerializer method near where the exception is thrown i put this snippet in
if(serializer == null)
{
foreach (var bsonSerializer in __serializers)
{
if(type.IsAssignableFrom(bsonSerializer.Key))
}
}
it will allow AsQueryable to use an interface type and deserialize it properly.