You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Microsoft.Data.SqlClient is not supported on this platform #2030
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
Create a new ASP.NET Core MVC project targeting .NET 7.
Create a new class library project targeting .NET 7.
Add a database context to the class library project using Microsoft.EntityFrameworkCore.SqlServer package.
Add a reference to the class library project in the MVC project.
Publish the MVC project and attempt to use the database context.
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.
Reacted by Tuomas Hietanen, Shawn Melton, tahirhan and Frulfump
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.
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).
Reacted by BenKung, Matt Abbas, PFox28, Theodoros Bebekis and Marco Nava
The Package Microsoft.Data.SqlClient has a Reference to Microsoft.Data.SqlClient.SNI.runtime. This Packages includes a native assembly, that is necessary for the SqlClient with net8.0.
However, if this native assembly is not present relative to the application (e.g. runtimes\win-x64\native), it will result in the "Microsoft.Data.SqlClient is not supported on this platform" exception.
We put our NuGet-Packages not next to our application, but in a separate folder with our own AssemblyLoadContext. We can load the Microsoft.Data.SqlClient.dll Assembly, and even the native Microsoft.Data.SqlClient.SNI.dll via AssemblyLoadContext.LoadUnmanagedDll, but still resulting in the error. If we move them to the outputfolder for the application (oder unit-test), it works. The crazy thing is, that i can access the imported functions and call them correctly like in SniNativeMethods.cs
For me it looks like, the resolving for the native assembly is buggy. But i dont find any related code in the repository.
Hi! Same problem here. It's driving me crazy, I don't know how to solve this issue. Everything was working in my project, had to update System.Data.Sqlclient because it was deprecated and the this nonesense started. Now going back to System. Data.Sqlclient and it shows me the same message.
In my case I have a main project for my app and then several projects that compile as libraries. Almost all projects reference the nuget. Then I have a visual studio setup project that generates the installer. Everything works properly, installs the app but throws the error. I don't really don't know what I have to do in my solution to really solve the issue.
Try to revert to the oldest version of System.Diagnostics
I had a similar problem when I built a DLL as an ADDIN for a graphics program (AutoCAD).
Another way, if you have a project/projects with Multi Target, create projects for each Target.
I'm running into this problem too. We have a library project whose assembly is resolved dynamically at runtime (like a plugin) into the main application, and it's this library that has a dependency on Microsoft.Data.SqlClient. I have confirmed that Microsoft.Data.SqlClient.dll is copied to the correct location for the hosting .NET application, and that the native runtimes/win-x64/native/Microsoft.Data.SqlClient.SNI.dll dependency exists too. But no amount of cajoling will get this thing to work without throwing a PlatformNotSupportedException. The only recourse is adding an artificial and unwanted dependency from the main application's project to Microsoft.Data.SqlClient. But why? Why does this work? What is this actually fixing? Why can't Microsoft.Data.SqlClient resolve its native dependencies like our other NuGet packages that have native dependencies? Those work fine, without a hack to add them to the main application as a direct dependency.
Since this issue is closed (despite continuing community feedback about recurring problems), will these comments even be observed by anybody at Microsoft who can perhaps look into it?
I have just now run into this problem too. I wanted to add my insight from my investigations in case they help point the community in the right direction.
Generally, in NuGet packages, the DLL in question we seek is located in the lib directory in a target framework moniker (TFM) sub-directory (.net6.0, .net7.0-windows, .net8.0-windows10.0.26100, etc.) inside your package. I think this is not true for this particular Microsoft.Data.SqlClient NuGet package. The package is found in the runtimes sub-directory, more specifically runtimes/win/lib/TFM (in my case runtimes/win/lib/net8.0).
If you were to install this package into a project via nuget.exe then you will see several copies of the Microsoft.Data.SqlClient.dll inside the downloaded resource. 1 in the aforementioned lib sub-directory (Microsoft.Data.SqlClient.6.1.4/lib/net8.0/Microsoft.Data.SqliClient.dll) which is not the one you want but is typically the one that NuGet finds if you are not a windows executable. If you were to open this one in any decompilation program (like dotPeek) you will see every declaration in every type simply throws a PlatformNotSupportException. They don't look at anything or inspect any parameters. 100% of everything just blindly throws a PNSE. This DLL in .NET8 is a little over 900KB.
Now the other DLL, in runtimes, is the one we want. This is the one that contains the goods (has the actual code and doesn't just throw PNSEs everywhere). So this DLL, (Microsoft.Data.SqlClient.6.1.4/runtimes/win/lib/net8.0/Microsoft.Data.SqliClient.dll), is the one that is typically found when we reference this NuGet package in a WinExe application. I think that is because of the EXE versus LIBRARY project types in terms of how NuGet.exe (and the newer dotnet variants) does resource lookup. This DLL in .NET8 is about 2.1MB. Big difference from the one that just throws a bunch of exceptions.
So if you reference this NuGet package in a DLL project it might never work right if MS doesn't change how the package is put together or how resource look ups work for DLL type projects within NuGet.
I am not a guru and I definitely don't understand this stuff at a low level. Just trying to add some insight as to why a lot us seem to be seeing this PlatformNotSupportException. Hope this helps someone out there. :)
I have just now run into this problem too. I wanted to add my insight from my investigations in case they help point the community in the right direction.
Generally, in NuGet packages, the DLL in question we seek is located in the lib directory in a target framework moniker (TFM) sub-directory (.net6.0, .net7.0-windows, .net8.0-windows10.0.26100, etc.) inside your package. I think this is not true for this particular Microsoft.Data.SqlClient NuGet package. The package is found in the runtimes sub-directory, more specifically runtimes/win/lib/TFM (in my case runtimes/win/lib/net8.0).
If you were to install this package into a project via nuget.exe then you will see several copies of the Microsoft.Data.SqlClient.dll inside the downloaded resource. 1 in the aforementioned lib sub-directory (Microsoft.Data.SqlClient.6.1.4/lib/net8.0/Microsoft.Data.SqliClient.dll) which is not the one you want but is typically the one that NuGet finds if you are not a windows executable. If you were to open this one in any decompilation program (like dotPeek) you will see every declaration in every type simply throws a PlatformNotSupportException. They don't look at anything or inspect any parameters. 100% of everything just blindly throws a PNSE. This DLL in .NET8 is a little over 900KB.
Now the other DLL, in runtimes, is the one we want. This is the one that contains the goods (has the actual code and doesn't just throw PNSEs everywhere). So this DLL, (Microsoft.Data.SqlClient.6.1.4/runtimes/win/lib/net8.0/Microsoft.Data.SqliClient.dll), is the one that is typically found when we reference this NuGet package in a WinExe application. I think that is because of the EXE versus LIBRARY project types in terms of how NuGet.exe (and the newer dotnet variants) does resource lookup. This DLL in .NET8 is about 2.1MB. Big difference from the one that just throws a bunch of exceptions.
So if you reference this NuGet package in a DLL project it might never work right if MS doesn't change how the package is put together or how resource look ups work for DLL type projects within NuGet.
I am not a guru and I definitely don't understand this stuff at a low level. Just trying to add some insight as to why a lot us seem to be seeing this PlatformNotSupportException. Hope this helps someone out there. :)
Well done researching this. Your conclusions seem very reasonable. It’s the perfect substantiation for the message I posted here a while back. 👍 I’m happy I understand this slightly better now.
Activity
JesLun commentedon May 3, 2023
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.Benknightdark commentedon May 4, 2023
Any solutions in windows environment?
JesperLundberg commentedon May 4, 2023
You'd need to find the runtime id for the windows you're using.
I found the Linux one somewhere in Microsofts documentation. Sorry that I can't be more specific.
Following the same logic as the Linux one it'd be
Windows-x64but I'm just guessing here.SudoCerb commentedon May 5, 2023
Microsoft's documentation that is linked by OP leads to a 404.
Great.
I have a similar issue. Creating it now and linking to this.
I'm on Windows 11.
JRahnama commentedon May 5, 2023
Could any one here provide a simple repro of the issue?
SudoCerb commentedon May 5, 2023
I'll happily do so - just need to create one. Will take a crack at this first thing in the morning.
SudoCerb commentedon May 5, 2023
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!
Kaur-Parminder commentedon May 10, 2023
I tried .Net7 ASP.NetCore WebAPP with class library targetting .NET7 on Windows 10. I am not seeing the exception, I am attaching the sample.
The steps I followed:
<ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> </ItemGroup>Scaffold-DbContext "Server=localhost;Database=Northwind;Integrated Security=true;Encrypt=false;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Modelsvar context = new NorthwindContext(); var test = context.Employees.First();Sample.zip
JesperLundberg commentedon May 11, 2023
Just to add to what I wrote earlier. The link where I found the RID for Linux is here.
Kaur-Parminder commentedon May 12, 2023
I set up on Ubuntu 22.04 with the same project. I can see data being fetched. .Net SDK 7.0.5 Runtime 7.0.203.
18 remaining items
shonuff373 commentedon May 16, 2024
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.
bh3605 commentedon Oct 15, 2024
.net 8 here. Still doesn't work.
Woudjee commentedon Nov 12, 2024
I HAVE A SOLUTION FOR WINDOWS PEOPLE:
This guy is right:
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).
mavToday commentedon Mar 6, 2025
The Package Microsoft.Data.SqlClient has a Reference to Microsoft.Data.SqlClient.SNI.runtime. This Packages includes a native assembly, that is necessary for the SqlClient with net8.0.
However, if this native assembly is not present relative to the application (e.g. runtimes\win-x64\native), it will result in the "Microsoft.Data.SqlClient is not supported on this platform" exception.
We put our NuGet-Packages not next to our application, but in a separate folder with our own AssemblyLoadContext. We can load the Microsoft.Data.SqlClient.dll Assembly, and even the native Microsoft.Data.SqlClient.SNI.dll via AssemblyLoadContext.LoadUnmanagedDll, but still resulting in the error. If we move them to the outputfolder for the application (oder unit-test), it works. The crazy thing is, that i can access the imported functions and call them correctly like in SniNativeMethods.cs
For me it looks like, the resolving for the native assembly is buggy. But i dont find any related code in the repository.
Add Setup project and direct reference to Microsoft.Data.SqlClient in…
NavirBox commentedon Oct 5, 2025
No way this is closed. It's still happening with 9.0
NintendoPlayer commentedon Feb 20, 2026
Hi! Same problem here. It's driving me crazy, I don't know how to solve this issue. Everything was working in my project, had to update System.Data.Sqlclient because it was deprecated and the this nonesense started. Now going back to System. Data.Sqlclient and it shows me the same message.
In my case I have a main project for my app and then several projects that compile as libraries. Almost all projects reference the nuget. Then I have a visual studio setup project that generates the installer. Everything works properly, installs the app but throws the error. I don't really don't know what I have to do in my solution to really solve the issue.
IzharAzati commentedon Feb 20, 2026
Try to revert to the oldest version of System.Diagnostics
I had a similar problem when I built a DLL as an ADDIN for a graphics program (AutoCAD).
Another way, if you have a project/projects with Multi Target, create projects for each Target.
prlcutting commentedon Feb 23, 2026
I'm running into this problem too. We have a library project whose assembly is resolved dynamically at runtime (like a plugin) into the main application, and it's this library that has a dependency on
Microsoft.Data.SqlClient. I have confirmed thatMicrosoft.Data.SqlClient.dllis copied to the correct location for the hosting .NET application, and that the nativeruntimes/win-x64/native/Microsoft.Data.SqlClient.SNI.dlldependency exists too. But no amount of cajoling will get this thing to work without throwing aPlatformNotSupportedException. The only recourse is adding an artificial and unwanted dependency from the main application's project toMicrosoft.Data.SqlClient. But why? Why does this work? What is this actually fixing? Why can'tMicrosoft.Data.SqlClientresolve its native dependencies like our other NuGet packages that have native dependencies? Those work fine, without a hack to add them to the main application as a direct dependency.Since this issue is closed (despite continuing community feedback about recurring problems), will these comments even be observed by anybody at Microsoft who can perhaps look into it?
AaronAmberman commentedon Feb 25, 2026
I have just now run into this problem too. I wanted to add my insight from my investigations in case they help point the community in the right direction.
Generally, in NuGet packages, the DLL in question we seek is located in the lib directory in a target framework moniker (TFM) sub-directory (.net6.0, .net7.0-windows, .net8.0-windows10.0.26100, etc.) inside your package. I think this is not true for this particular Microsoft.Data.SqlClient NuGet package. The package is found in the runtimes sub-directory, more specifically runtimes/win/lib/TFM (in my case runtimes/win/lib/net8.0).
If you were to install this package into a project via nuget.exe then you will see several copies of the Microsoft.Data.SqlClient.dll inside the downloaded resource. 1 in the aforementioned lib sub-directory (Microsoft.Data.SqlClient.6.1.4/lib/net8.0/Microsoft.Data.SqliClient.dll) which is not the one you want but is typically the one that NuGet finds if you are not a windows executable. If you were to open this one in any decompilation program (like dotPeek) you will see every declaration in every type simply throws a PlatformNotSupportException. They don't look at anything or inspect any parameters. 100% of everything just blindly throws a PNSE. This DLL in .NET8 is a little over 900KB.
Now the other DLL, in runtimes, is the one we want. This is the one that contains the goods (has the actual code and doesn't just throw PNSEs everywhere). So this DLL, (Microsoft.Data.SqlClient.6.1.4/runtimes/win/lib/net8.0/Microsoft.Data.SqliClient.dll), is the one that is typically found when we reference this NuGet package in a WinExe application. I think that is because of the EXE versus LIBRARY project types in terms of how NuGet.exe (and the newer dotnet variants) does resource lookup. This DLL in .NET8 is about 2.1MB. Big difference from the one that just throws a bunch of exceptions.
So if you reference this NuGet package in a DLL project it might never work right if MS doesn't change how the package is put together or how resource look ups work for DLL type projects within NuGet.
I am not a guru and I definitely don't understand this stuff at a low level. Just trying to add some insight as to why a lot us seem to be seeing this PlatformNotSupportException. Hope this helps someone out there. :)
Woudjee commentedon Feb 25, 2026
Well done researching this. Your conclusions seem very reasonable. It’s the perfect substantiation for the message I posted here a while back. 👍 I’m happy I understand this slightly better now.
bootrider commentedon Jul 23, 2026
It is still happening in the version 7.0.1.
bootrider commentedon Jul 23, 2026
this solve my issue:
Making the upgrade from .NET8 to .NET10 I had:
I changed to: