Core: MongoDB Driver Exception in Preview 4

Created on 19 Apr 2019  Â·  12Comments  Â·  Source: dotnet/core

I installed .NET Core Preview 4, startup my app, and received this exception. This is a .NET Core Console Application that is referencing an object in a .NET Standard Library. The types all appear appear in the debugger however the mongo driver throws this exception.

I moved back to .NET Core Preview 3, recompiled, and there is no issue.

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'MongoDB.Bson.Serialization.BsonClassMap' threw an exception.
  Source=MongoDB.Bson
  StackTrace:
   at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
   at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer[T]()
   at MongoDB.Driver.MongoCollectionImpl`1..ctor(IMongoDatabase database, CollectionNamespace collectionNamespace, MongoCollectionSettings settings, ICluster cluster, IOperationExecutor operationExecutor)
   at MongoDB.Driver.MongoDatabaseImpl.GetCollection[TDocument](String name, MongoCollectionSettings settings)
   ...

Inner Exception 1:
ArgumentNullException: Value cannot be null.
Parameter name: type
needs-more-info

Most helpful comment

a fix was done but not yet merged to the master branch nor branch 2.8
https://github.com/mongodb/mongo-csharp-driver/pull/372

All 12 comments

Are you able to compare working and non-working repro side by side to figure out what changed between those 2?
We need to narrow down which API behavior change in .NET Core caused the misbehaior. It is also possibility (albeit small) that it is a bug in the library, or elsewhere ...

I think this be the problem.

MongoDB driver needs a reference to System.Runtime.Serialization.Formatters.

Are you able to compare working and non-working repro side by side to figure out what changed between those 2?
We need to narrow down which API behavior change in .NET Core caused the misbehaior. It is also possibility (albeit small) that it is a bug in the library, or elsewhere ...

I installed .NET Core Preview 4, startup my app, and received this exception. This is a .NET Core Console Application that is referencing an object in a .NET Standard Library. The types all appear appear in the debugger however the mongo driver throws this exception.

I moved back to .NET Core Preview 3, recompiled, and there is no issue.

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'MongoDB.Bson.Serialization.BsonClassMap' threw an exception.
  Source=MongoDB.Bson
  StackTrace:
   at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType)
   at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer[T]()
   at MongoDB.Driver.MongoCollectionImpl`1..ctor(IMongoDatabase database, CollectionNamespace collectionNamespace, MongoCollectionSettings settings, ICluster cluster, IOperationExecutor operationExecutor)
   at MongoDB.Driver.MongoDatabaseImpl.GetCollection[TDocument](String name, MongoCollectionSettings settings)
   ...

Inner Exception 1:
ArgumentNullException: Value cannot be null.
Parameter name: type

I faced the same exception after upgrading to .net 3.0 preview 4 , it was working fine with preview 3

I've the same issue on 3.0 preview 4. Is there any solution?

a fix was done but not yet merged to the master branch nor branch 2.8
https://github.com/mongodb/mongo-csharp-driver/pull/372

Looks like external problem, with solution. Closing.

@mostafa-tag will the PR be merged in the future?

@ebekker what did you do to fix the problem?

I believe it should be merged because the fix was made by @KonHhttps://github.com/KonH via a pull request on the master branch .

Mostafa Tag-

From: Malavos notifications@github.com
Sent: Monday, April 29, 2019 6:01 PM
To: dotnet/core core@noreply.github.com
Cc: Mostafa Tag MTag@integrant.com; Mention mention@noreply.github.com
Subject: Re: [dotnet/core] MongoDB Driver Exception in Preview 4 (#2611)

@mostafa-taghttps://github.com/mostafa-tag will the PR be merged in the future?

@ebekkerhttps://github.com/ebekker what did you do to fix the problem?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/dotnet/core/issues/2611#issuecomment-487638597, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACTHMZJ6EA7FM3WZZW45YFLPS4LULANCNFSM4HHIBL4Q.

@mostafa-tag thank you. I have also made contact with one of the maintainers of the mongo driver. Let's wait for their input now.

The fix in the PR looks like it will address the issue by referencing the missing Serialization.Formatters package. For the time being I've reverted back to the preview 3 until the change is officially released in the MongoDB driver -- don't want to mess around with building my version, it would be overkill for my current needs.

I am facing same problem in version 2.8 even i have downgrade project to 2.7.3 problem same but no problem with 2.7.2 old version. But Now 2.7.2 again errorrr

Was this page helpful?
0 / 5 - 0 ratings