Microsoft.Data.SqlClient is not supported on this platform

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
JesLuncommented, 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.

2reactions
SudoCerbcommented, 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found