Summary
After update the mongo db driver library from version 3.1.0 to 3.2.0 one of our application stopped to work. Attempt to read existing data or to write the new one (after cleaning up database) causes "stack overflow" and application termination. I suspect that the problem is with BSON model, where one of documents contains "tree-structure" (nested reference to type declaring it). When I have commented "problematic" declaration in document, application started to work.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
How to Reproduce
- Apply version `3.2.0` of the driver.
- Create document definition containing self type reference, in my case it was something like:
public class QuestionnaireMetadataVm { public string Id { get; set; } public string Status { get; set; } public string Locale { get; set; } public string Name { get; set; } public List<CategoryVm> Categories { get; set; } } public class CategoryVm { public string Id { get; set; } public string Name { get; set; } public CategoryVm Category { get; set; } }
- Register ObjectSerializers with code: "
BsonSerializer.TryRegisterSerializer(new ObjectSerializer(_ => true));
(in my case during Startup following registration):
public static class Extensions { public static IAppBuilder AddBsonClassMapping(this IAppBuilder app) { BsonSerializer.TryRegisterSerializer(new ObjectSerializer(_ => true)); return app; } }
- Add code that either tries to fetch from or write do db data (if read - data has to exist):
// read var docJson = await db .GetCollection<ListJson<T>>("ListJson") .Find(doc => doc.Id == id) .SingleOrDefaultAsync(cancellationToken); // write await db.GetCollection<ListJson<T>>("ListJson").ReplaceOneAsync(doc => doc.Id == id, new ListJson<T> { Id = id, Elements = elements }, new ReplaceOptions { IsUpsert = true }, cancellationToken);
- In my case, application terminates execution with stack overflow, more detail in copied console logs.
Additional Background
I enclose full logs I am able to gain, but the most crucial moment IMHO is:
at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(System.Type) at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer(System.Type) at MongoDB.Bson.Serialization.BsonMemberMap.GetSerializer() at MongoDB.Bson.Serialization.Conventions.EnumRepresentationConvention.Apply(MongoDB.Bson.Serialization.BsonMemberMap) at MongoDB.Bson.Serialization.Conventions.ConventionRunner.Apply(MongoDB.Bson.Serialization.BsonClassMap) at MongoDB.Bson.Serialization.BsonClassMap.AutoMapClass() at MongoDB.Bson.Serialization.BsonClassMap.AutoMap() at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(System.Type) at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(System.Type, MongoDB.Bson.Serialization.IBsonSerializerRegistry) at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(System.Type) at System.Collections.Concurrent.ConcurrentDictionary`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(System.__Canon, System.Func`2<System.__Canon,System.__Canon>) at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(System.Type) at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer(System.Type) at MongoDB.Bson.Serialization.BsonMemberMap.GetSerializer() at MongoDB.Bson.Serialization.Conventions.EnumRepresentationConvention.Apply(MongoDB.Bson.Serialization.BsonMemberMap) at MongoDB.Bson.Serialization.Conventions.ConventionRunner.Apply(MongoDB.Bson.Serialization.BsonClassMap) at MongoDB.Bson.Serialization.BsonClassMap.AutoMapClass() at MongoDB.Bson.Serialization.BsonClassMap.AutoMap() at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(System.Type) at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(System.Type, MongoDB.Bson.Serialization.IBsonSerializerRegistry) at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(System.Type) at System.Collections.Concurrent.ConcurrentDictionary`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(System.__Canon, System.Func`2<System.__Canon,System.__Canon>) at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(System.Type) at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]() at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`2+<>c__DisplayClass4_0[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<.ctor>b__0() at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode) at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean) at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue() at MongoDB.Bson.Serialization.Serializers.EnumerableSerializerBase`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, S ystem.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Deserialize(MongoDB.Bson.Serialization.BsonDeserializationContext, MongoDB.Bson.Serialization.BsonDeserializationArgs)
- is caused by
-
CSHARP-2096 Make EnumRepresentationConvention also affect collections of Enums
-
- Closed
-
-
CSHARP-4495 Add conventions and attributes to configure ObjectSerializer AllowedTypes
-
- Closed
-