Skip to content
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

The name passed to DbProviderFactories.GetFactory is case sensitive but the error message indicates the name is "invariant" which isn't correct #110236

Closed
icnocop opened this issue Nov 28, 2024 · 6 comments

Comments

@icnocop
Copy link

icnocop commented Nov 28, 2024

Description

In .NET Framework the data provider factory name is case insensitive, but in .NET 8 at least, the name is now case sensitive, but the error message hasn't been updated to reflect the breaking change.

Reproduction Steps

<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />

DbProviderFactories.RegisterFactory("System.Data.SqlClient", Microsoft.Data.SqlClient.SqlClientFactory.Instance);

DbProviderFactory factory = DbProviderFactories.GetFactory("system.data.sqlclient");

Expected behavior

I expected the provider name to not be case sensitive, or the error message to be updated.

Actual behavior

System.ArgumentException: The specified invariant name 'system.data.sqlclient' wasn't found in the list of registered .NET Data Providers.
Stack Trace: 
DbProviderFactories.GetFactory(String providerInvariantName, Boolean throwOnError)
DbProviderFactories.GetFactory(String providerInvariantName)

Regression?

Yes, it worked in .NET Framework 4.7.2.

Known Workarounds

As a work-around, register providers using all lower-case characters, and then call DbProviderFactory factory = DbProviderFactories.GetFactory(providerName.ToLower()); for example.

Configuration

.NET 8
Windows 10 64-bit

Other information

return throwOnError ? throw ADP.Argument(SR.Format(SR.ADP_DbProviderFactories_InvariantNameNotFound, providerInvariantName)) : (DbProviderFactory?)null;

https://github.com/dotnet/dotnet/blob/83244d9bd58049da40ce5a822579735dc8ba1f4d/src/runtime/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactories.cs#L154

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 28, 2024
Copy link
Contributor

Tagging subscribers to this area: @roji, @ajcvickers
See info in area-owners.md if you want to be subscribed.

@roji
Copy link
Member

roji commented Nov 28, 2024

Makes sense, looks like the error message needs to be fixed.

@roji roji removed the untriaged New issue has not been triaged by the area owner label Nov 28, 2024
@roji roji added this to the Future milestone Nov 28, 2024
@KalleOlaviNiemitalo
Copy link

I'd think "invariant" there just means the name does not depend on language settings, and that "invariant" does not imply that the name is case-insensitive.

@roji
Copy link
Member

roji commented Nov 29, 2024

@KalleOlaviNiemitalo agreed about invariant, but the exception message seems to show a lower-case version of the invariant name system.data.sqlclient, which seems wrong.

@KalleOlaviNiemitalo
Copy link

@roji, the "Reproduction Steps" in the issue description have the lower-case name in DbProviderFactories.GetFactory("system.data.sqlclient"), so to me it's OK to show the same in the exception message.

@roji
Copy link
Member

roji commented Nov 30, 2024

@KalleOlaviNiemitalo oh I see - I read the original issue a bit too quickly, thanks for correcting me on that.

@icnocop if your suggestion/request is indeed to update the exception message to remove the word "invariant" there, then as @KalleOlaviNiemitalo wrote above, invariant does not mean "case-insensitive", and it makes for it to stay there. I'll go ahead and close this issue with that assumption, but feel free to post back here if I've misunderstood or you have further comments.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2024
@roji roji removed this from the Future milestone Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants