Skip to content

Bring back support for netstandard2.0 #1675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RogerBarreto
Copy link

When attempting to update to the latest driver we stumbled into a limitation that was not before until major 3.0 dropping support for netstandard 2.0.

In the good willingness to bring this support back I'm proposing this PR.

Thanks

@RogerBarreto RogerBarreto requested a review from a team as a code owner April 23, 2025 19:09
@RogerBarreto RogerBarreto requested review from adelinowona and removed request for a team April 23, 2025 19:09
@damieng
Copy link
Member

damieng commented Apr 25, 2025

Hi.

We removed netstandard2.0 for a bunch of reasons, not least of all the missing Cryptography mechanism. I don't think we'd want to bring in vendored code and have to change the Apache licence of the project to a mixed-licence project without an incredibly strong justification.

Is there some platform missing that netstandard2.1;net472;net6.0 isn't enabling for you?

@damieng damieng self-assigned this Apr 25, 2025
@RogerBarreto
Copy link
Author

RogerBarreto commented Apr 25, 2025

@damieng I work in Semantic Kernel, a SDK for AI maintained by Microsoft and we do have a connector there for MongoDB, and is a very good standard to have projects that support netstandard2.0 which allow a huge code base including .Net Framework from 4.0 up to 4.8, basically in our MongoDB connector we are stuck to the latest version of 2.3.0 where netstandard 2.0 was still supported.

@damieng
Copy link
Member

damieng commented Apr 25, 2025

At the time when we looked at usage statistics there was not enough usage below 4.7.2 to justify any extra effort there. Given the Semantic Kernel connector for MongoDB is a separate package to SK itself would it not just make sense for that project to target netstandard 2.1?

@damieng
Copy link
Member

damieng commented Apr 25, 2025

If you want to talk offline you can message me directly on the Microsoft corporate Teams (I'm a Guest so I can't initiate the conversation there).

@JamesKovacs
Copy link
Contributor

There is an additional problem with using netstandard2.0 assemblies with .NET Framework 4.7+. ObjectId.GenerateNewId() relies on System.Random. On .NET Framework, System.Random instances are initialized with the current system ticks. On .NET Core, System.Random instances are initialized via a cryptographically-secure RNG. Consider this code:

var rnd1 = new Random();
var rnd2 = new Random();

On .NET Core, these two instances will output different PRNG sequences but on .NET Framework the two instances will generate the same PRNG sequence.

While we could consider fixing .NET Framework to initialize Random (used for ObjectId generation) to also use cryptographically-secure seed, there are other places in the code where netstandard2.0 differs from net472, such as our networking stack.

Thus it wouldn't be as simple as re-introducing netstandard2.0 support, but carefully testing all our netstandard2.0 code to make sure it is compatible with .NET Framework - much of which would require runtime checks.

Our current direction is to use net472 for .NET Framework 4.7+ and netstandard2.1/net60/etc. for .NET Core (which includes .NET 5+). Hopefully that explanation helps you understand our decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants