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.SqlClient NuGet package;
- Add this line of code
SqlClientFactory.Instance.CreateConnection();
- Build;
- Open the
[app].deps.json file using Notepad and remove "runtimeTargets" under "Microsoft.Data.SqlClient/7.0.0";
- Run the application;
- A
NullReferenceException is 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
Describe the bug
The
Microsoft.Data.SqlClient.dllassembly that is copied to the output folder on a build contains stubs that throw aPlatformNotSupportedExceptionwith 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 theruntimesfolder.However, if this assembly loading from the
runtimesfolder does not succeed, for example when thedeps.jsonfile omits the correctruntimeTargets, the facade assembly is used.As said, the assembly usually throws an exception on all methods, but not on calling the
SqlClientFactory.Instancefield. Although this field is marked not to benull, it is when only loading the facade assembly.This results in a
NullReferenceExceptionon callingSqlClientFactory.Instance.CreateConnection()and others.To reproduce
Microsoft.Data.SqlClientNuGet package;SqlClientFactory.Instance.CreateConnection();[app].deps.jsonfile using Notepad and remove"runtimeTargets"under"Microsoft.Data.SqlClient/7.0.0";NullReferenceExceptionis thrown.Expected behavior
A clear exception, for example by converting
Instanceto 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