-
Notifications
You must be signed in to change notification settings - Fork 323
Description
Describe the bug
The Microsoft.Data.SqlClient.dll assembly that is copied to the output folder on a build contains stubs that throw a PlatformNotSupportedException with the text "Microsoft.Data.SqlClient is not supported on this platform." on all relevant methods. This is intended since the correct assembly and its dependencies are loaded from the runtimes folder.
However, if this assembly loading from the runtimes folder does not succeed, for example when the deps.json file omits the correct runtimeTargets, the facade assembly is used.
As said, the assembly usually throws an exception on all methods, but not on calling the SqlClientFactory.Instance field. Although this field is marked not to be null, it is when only loading the facade assembly.
This results in a NullReferenceException on calling SqlClientFactory.Instance.CreateConnection() and others.
To reproduce
- Create a console application;
- Add the
Microsoft.Data.SqlClientNuGet package; - Add this line of code
SqlClientFactory.Instance.CreateConnection(); - Build;
- Open the
[app].deps.jsonfile using Notepad and remove"runtimeTargets"under"Microsoft.Data.SqlClient/7.0.0"; - Run the application;
- A
NullReferenceExceptionis thrown.
Expected behavior
A clear exception, for example by converting Instance to a property and throw an exception, or throw the exception from a static constructor.
Further technical details
Microsoft.Data.SqlClient version: 7.0.0
.NET target: .NET 10.0
Metadata
Metadata
Assignees
Labels
Type
Projects
Status