SqlClient: Microsoft.Data.SqlClient is not supported on this platform

Issue Description

I have an ASP.NET Core MVC project targeting .NET 7 and a library project also targeting .NET 7. After referencing the library project in the MVC project and publishing it, I receive the following error when trying to use the DbContext:

System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.

Expected Behavior

I expected to be able to use the DbContext without any issues after referencing the .NET 7 library project.

Steps to Reproduce

  1. Create a new ASP.NET Core MVC project targeting .NET 7.
  2. Create a new class library project targeting .NET 7.
  3. Add a database context to the class library project using Microsoft.EntityFrameworkCore.SqlServer package.
  4. Add a reference to the class library project in the MVC project.
  5. Publish the MVC project and attempt to use the database context.

Additional Information

  • I have tried the solutions suggested in Microsoft’s documentation.
  • I have also tried downgrading the class library project to target .NET 6 and that resolved the issue. However, I need to target .NET 7 for other reasons.
  • This is a severe issue as it prevents me from using a library project that targets .NET 7 and Microsoft.Data.SqlClient.
  • This issue did not occur when using .NET 6 in both projects.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 29 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I have this issue as well and also had it on .net 6 when running it on Linux.

I found a workaround which is to send the runtime identifier. Like this dotnet run -r linux-x64.

Any solutions in windows environment?

I HAVE A SOLUTION FOR WINDOWS PEOPLE:

This guy is right:

I also had this problem when upgrading from .NET 7.0 to .NET 8.0. Adding the nuget package <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> To the executing application csproj fixed it. Why I don’t know.

Why? I’m not sure, but I believe that it has something to do with our sql projects being class libs instead of applications, thereby messing up package references. I have had similar problems with different packages some times. It has something to do with how the project is build for production being different than the project being build for debugging purposes. When debugging, all dll’s are copied to the right place, when creating a release, they don’t. This is something that is supposed to be fixed on the Microsoft side, like @RobDaytona was complaning about. I can relate to what you’re writing very well man.

So to solve these and similar issues: make sure that you reference the missing dll in your calling project, and most likely you’re good to go. (I used the latest version).

In my case, adding to .csproj file:

<!--see: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#copylocallockfileassemblies  -->
**<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>**
<!--<ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>-->
<!--<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>-->
**<RuntimeIdentifier>win-x64</RuntimeIdentifier>**

managed to make it work. (SQL, ODBC, …) In my case, I’m developing a DLL plugin for the AutoCAD software, the problem is that all Microsoft’s tests / examples are for EXE applications and not for DLLs.

I just don’t understand how any one is supposed to develop using Microsoft .net technologies any more. The stuff is so buggy it drives me insane. Yesterday my API was working perfectly accessing stored procs no problems, today first thing it says is: Microsoft.Data.SqlClient is not supported on this platform #2030 and the only thing that has changed is I implemented bearer token security into the api call? so no mods whatsover with sql sever… or anything database related and I am getting “Microsoft.Data.SqlClient is not supported on this platform” - wtf I have an app to write and I am constantly running into issues all the time. does my head in. I have basic bugs open in .net Maui, that get verified as bugs, and previously xamarin, I report the bug, the bug gets verified, then never fixed… this is ridiculous. Does any one have any ideas what is causing this issue? and or recommendations on what to fix, this thread is very confusing with people on about linux etc… my situation is .net8, .net aspcore api project (or whatever its called these days)… running on a dedicated API dns on a windows 2016 server… so where is the issue? is it the api project ? or is it the server, and why did this work yesterday and today after implementing token bearer security on the api call it does this? its madness… aaaaargg!!! I am ging to revert to a back up from yesterday that does not include any of the token/bearer security code I implemented today to see if it suddenly works? I can’t see why token bearer security would have anything to do with this error message… aaargg!

Did someone manage to get this working for Windows?

Windows 11, Visual Studio 2022, .NET Standard 2.0 Class Library project

On Mint/Ubuntu it seems to be an issue with the Ubuntu versions of Dotnet. I replaced them with the Microsoft packages from https://packages.microsoft.com/ubuntu/22.04/prod and all is now fine. [Instructions at https://learn.microsoft.com/en-ca/dotnet/core/install/linux-ubuntu#register-the-microsoft-package-repository]

Hi @JRahnama , I’ve created the simplest case I could -

https://github.com/SudoCerb/manictime-microsoft.data.sqlclient-min-repro

Instructions are in the README.md.

I hope that this helps!

I also had this problem when upgrading from .NET 7.0 to .NET 8.0. Adding the nuget package <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> To the executing application csproj fixed it. Why I don’t know.

I’m running into the same issue for the same reason. I read on a few other forums that downgrading to 5.1.5 helped. But that hasn’t worked for me.

I also had this problem when upgrading from .NET 7.0 to .NET 8.0. Adding the nuget package <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> To the executing application csproj fixed it. Why I don’t know.

Detecting the correct target framework is on runtime to be discovered not MDS. Any failed attempts will fall back to the “not supported platform” dll and throw this exception which is by design.

I think it would be quite useful for the error to say something like that. I have no idea how to get around this but that error message would have been more helpful!