dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
854 stars 286 forks source link

Application that targets .NET 4.8 does not support System.Data.SqlClient that targets .NET Standard 2.0 #2840

Open tdGreat opened 2 months ago

tdGreat commented 2 months ago

I have a dll (say TestLib.dll) that targets .NET Standard 2.0, which uses System.Data.SqlClient dll (this also targets .NET Standard 2.0).

Now I'm using the TestLib.dll in an application (say TestApp) that targets .NET 4.8. Running the application results in an exception

System.Data.SqlClient is not supported on this platform

It is because TestApp was loading the System.Data.SqlClient.dll that targets .NET Standard.

If I give the reference to the the System.Data.SqlClient.dll that targets .NET 4.6.1, it works.

To reproduce the issue:

  1. Create a class library that targets .NET Standard 2.0 (TestLibrary)
  2. In the TestLibrary, reference and use SqlClient (which targets .NET Standard 2.0) latest version (4.8.6) and create a function to query something from the database
  3. Build/publish the TestLibrary
  4. Create a console application (TestApp) with .NET 4.8 as target framework and use that class library
  5. Invoke the function that is querying the database Note: make sure TestApp is referencing SqlClient that targets .NET Standard 2.0.

When it tries to create a connection object, the exception occurs.

What is the reason for .NET 4.8 not supporting the SqlClient dll that targets .NET Standard 2.0?

arellegue commented 2 months ago

Have you tried to use Microsoft.Data.SqlClient?

We will look into this and get back to you soon.