Microsoft.Data.SqlClient is not supported on this platform
See original GitHub issueIssue 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
- 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.
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.
Issue Analytics
- State:
- Created 5 months ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Microsoft.Data.SqlClient is not supported on this platform
Microsoft.Data.SqlClient is not supported on this platform. When using the portal to create Azure function in C#, System.Data.
Read more >How to resolve "Microsoft.Data.SqlClient is not supported on ...
How to fix error “Microsoft.Data.SqlClient is not supported on this platform.” · Downgrade your .NET or dependency version · Downgrading isn't ...
Read more >System.Data.SqlClient is not supported on this platform
Setting System.Data.SqlClient as a Nuget dependency in the controlling service works OK and the library is loaded correctly without error.
Read more >Solved: Addin Module error: System.Data.SqlClient is not s...
Data.SqlClient is not supported on this platform' when I try to use a System.Data.SqlClient.SqlConnection object.
Read more >How to Fix 'Microsoft.Data.SqlClient is not Supported on this ...
1. Downgrade your .NET or dependency version · 2. Downgrading isn't feasible? Make sure you're on the latest version! · 3. Set your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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!