[CSHARP-2595] BsonClassMap type initializer throws exception Created: 19/Apr/19  Updated: 28/Oct/23  Resolved: 14/May/19

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.8.0
Fix Version/s: 2.8.1

Type: Bug Priority: Major - P3
Reporter: Konstantinos Sambanis Assignee: Robert Stam
Resolution: Fixed Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

dotnet core 3.0 preview4


Issue Links:
Related
is related to CSHARP-2592 Add .NET Standard 2.0 support Closed

 Description   

The exception is thrown at: https://github.com/mongodb/mongo-csharp-driver/blob/660658d4253f06506c1d60aae7ef68745ab609b2/src/MongoDB.Bson/Serialization/BsonClassMap.cs#L40

 

It used to work up to and including dotnet core 3.0 preview3.

 

Today I upgraded to preview4, causing this breaking change.

I researched the issue briefly, apparently the new core version does not include the System.Runtime.Serialization.Formatters reference in CoreLib (so the System.Runtime.Serialization.FormatterServices type cannot be loaded this way).

 

Assembly.Load("System.Runtime.Serialization.Formatters") will work instead of  typeof(string).GetTypeInfo().Assembly as a method to load the assembly, but it will not work with .net framework (so there is some versioning code required probably).



 Comments   
Comment by Githook User [ 20/May/19 ]

Author:

{'name': 'vincentkam', 'email': 'vincent.kam@10gen.com', 'username': 'vincentkam'}

Message: CSHARP-2595: Update contributors list
Branch: v2.8.x
https://github.com/mongodb/mongo-csharp-driver/commit/970f8df1ef7b9825d28f8b5354f1568d0945b2b4

Comment by Githook User [ 17/May/19 ]

Author:

{'name': 'vincentkam', 'email': 'vincent.kam@10gen.com', 'username': 'vincentkam'}

Message: CSHARP-2595: Update contributors list
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e06d93619173311cfa3c40504e07536797d4888e

Comment by Githook User [ 13/May/19 ]

Author:

{'email': 'robert@robertstam.org', 'name': 'rstam', 'username': 'rstam'}

Message: CSHARP-2595: Refactor BsonClassMap to work around changes in .NET Core 3.0.
Branch: v2.8.x
https://github.com/mongodb/mongo-csharp-driver/commit/2cedfa5d1aa254257299b590794dd102612f924a

Comment by Githook User [ 13/May/19 ]

Author:

{'email': 'konh@yandex.ru', 'name': 'KonH', 'username': 'KonH'}

Message: CSHARP-2595: Fix initialization on .NET Core 3.0 preview 4.

This change cover .NET Framework and .NET Core ways to get System.Runtime.Serialization.FormatterServices type instance.
Branch: v2.8.x
https://github.com/mongodb/mongo-csharp-driver/commit/53073cb5feed92f33af22886e050abd0e1ee0b03

Comment by Githook User [ 13/May/19 ]

Author:

{'email': 'robert@robertstam.org', 'name': 'rstam', 'username': 'rstam'}

Message: CSHARP-2595: Refactor BsonClassMap to work around changes in .NET Core 3.0.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/8483a6f0101829dbc1e82bc7928e2c84aba9b028

Comment by Githook User [ 13/May/19 ]

Author:

{'email': 'konh@yandex.ru', 'name': 'KonH', 'username': 'KonH'}

Message: CSHARP-2595: Fix initialization on .NET Core 3.0 preview 4.

This change cover .NET Framework and .NET Core ways to get System.Runtime.Serialization.FormatterServices type instance.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a2b2bb16e7c55d24b4530517f81d3db3d7bd1b38

Comment by Konstantin Khitrykh [ 20/Apr/19 ]

Hello! I submitted PR with proposed changes - https://github.com/mongodb/mongo-csharp-driver/pull/372

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