System.Data.SqlClient is not supported on this platform
Asked Answered
G

12

24

I'm using ASP.NET Core 2 with Entity Framework Core 2.0.2. I created a context and Add-Migrations command in Package Manager Controller works fine.

However when Update-Database command is used, I get an error:

System.Data.SqlClient is not supported on this platform

I can't figure out where the problem is. Can you help me? Thanks.

My .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <DebugType>portable</DebugType>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="2.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
  </ItemGroup>

</Project>
Grizzle answered 19/3, 2018 at 3:50 Comment(5)
Could you post the contents of the .csproj file(s)?Noctule
csproj .csproj file of my projectGrizzle
No links please - edit your question and post the code in it. Without code, this question is off topic and will likely be closed. See How to Ask. Ideally, there would be enough code in your question to duplicate the problem.Noctule
Sorry about that and thanks.Grizzle
look at this issue from github github.com/dotnet/corefx/issues/24229Mucosa
R
19

I ran into the same issue a couple of days ago - I'm not sure what the underlying issue is, but reverting some of the EntityFrameworkCore nuget packages back to 2.0.0 seems to have resolved the issue for me. These are the packages I downgraded:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
Reflation answered 22/3, 2018 at 19:35 Comment(4)
Yeah, That solved my issue too. I was able to solve my issue while play around with different versions of Microsoft.EntityFrameworkCore . Sorry about late reply I was buys with my project for days now.Grizzle
@robs, did you find the solution? I am not using EF in my projects. Thank you.Hum
In my case, downgrading System.Data.SqlClient in NuGet from 4.8.1 to 4.1.0 fixed it. This might have worked for other versions between 4.8 and 4.1 but I didn't have time to test.Duester
August 2021 and this is still the solution. Wow. I ended up with a .NET Core 2.0 console app and a models project (.NET Standard 2.0) that used EF Tools and EF SqlServer. I had to downgrade both of the EF packages to 2.0.0Vandenberg
G
14

Same problem here but for me it is a failure on the part of System.Data.SqlClient to load dynamically as part of a plugin. Our plugin dlls are loaded dynamically via Autofac and a controlling service selects the correct one at run time. Unfortunately System.Data.SqlClient will not load dynamically like this, result in the above error message. So I had to load it when the controlling service starts up. This is obviously not ideal but for now it is a usable workaround as all our plugins are still under our control.

I'll be more specific, following a question in comments.

A service selects plug-ins at run time. The plug-ins register their own dependencies via Autofac and if that dependency is a Nuget package they will also include the package as a normal Nuget dependency.

The controlling service registers the plug-in dlls on start up and the first time they are used the plug-in dependencies are also loaded. When System.Data.SqlClient load is attempted following a call to the plug-in that uses SqlClient the "not supported" error results.

Setting System.Data.SqlClient as a Nuget dependency in the controlling service works OK and the library is loaded correctly without error. However, this is not ideal because the the SqlClient library always has to be loaded by the controlling service even if the plug-in selected to run it does not need it.

In other words the SqlClient library is always loaded at service start up occupying resources, etc when it may not even be needed. But at least it works.

Gurney answered 3/4, 2019 at 5:20 Comment(3)
"So I had to load it" - what do you mean?Hum
If Microsoft.Data is to be used in place of System.Data in .NET Core 3.1 then why IDbConnection still showing error ? Who to implement Repository Pattern in that case using .NET core ?Valentia
@Gurney Same problem here, but trying the proposed solution didn't work for me. I've a similar solution, with many projects (.NET Core 2.1 and .NET Standard). My Domain Objects project with Entities and Migrations is .NET Core 2.1 but it's not the Main (startup) project. So I also had to use the IDesignTimeDbContextFactory implementation "trick" to enable the migrations. My Main (startup project) uses UnityContainer for Dependency Injection and for DLL dynamic loading.Toffey
F
7

I ran into this issue recently with .net standard 2.0 classes being consumed by a regular .net framework app. (.net 4.7.x). The only thing that ultimately fixed my issue was migrating from packages.config to PackageReference on the regular .net app.

Firry answered 25/3, 2019 at 18:17 Comment(3)
ByPackageReference all the dependencies have been managed. Therefore You do not need to check the individual dependencies. By using PackageReference dependencies may have been managed.Grizzle
Also I'm not developing anything using .net nearly for year. Above comment was what I just though about the case of solution.Grizzle
I googled about migrating to PackageReference and found that link was useful for me. devblogs.microsoft.com/nuget/…Takao
J
3

Just in case somebody lands here who is trying to run System.Data.SqlClient on net50/netstandard on rid freebsd-x64: Microsoft.Data.SqlClient worked for me.

Maybe this works on every portable option and/or for all System.[...] ->Microsoft.[...] dll.

Jahncke answered 10/11, 2020 at 11:41 Comment(0)
B
2

I spent a couple of hours on this but managed to resolve it. Posting here in case it helps someone else save some time.

In my .csproj files I had

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

Removing this solved my problem. Some information can be found here. Setting the value to true causes all dependencies to be copied to the output folder and for me, maybe when loading the application, it was getting confused about which System.Data.SqlClient.dll to load.

Burp answered 18/6, 2021 at 6:22 Comment(0)
G
1

I had this exact same issue with a .NET 5.0 console application i was deploying. I discovered that when i published the application the publish profiles target framework was set to 3.1 instead of 5.0 and that is what caused this error for me. After re-publishing with the correct target framework everything worked as expected.

Giulietta answered 19/8, 2021 at 16:54 Comment(0)
B
0

If you copy the dll from the unzipped nupkg package and got this error, make sure you use the right one with included dependencies like System.Runtime ... :

~/runtimes/unix or win/lib/netcoreapp2.1 

for e.g. .net6.0

Birgitbirgitta answered 2/3, 2023 at 14:19 Comment(0)
B
0

For me, it got resolved by having the runtimes subdirectory available within the used bin directory (using .net 6.0 and Microsoft.EntityFrameworkCore.SqlServer Version="7.0.7" )

Burden answered 21/7, 2023 at 7:19 Comment(0)
G
0

I was in the exact same situation, add-migration works fine, but update-database get the "SqlClient Not wupported on this platform" error. I am using linux (Pop!_OS).

The accepted solution didn't work for me, so I tried a lot of alternatives.

The solution for me was to add <RuntimeIdentifier>linux-x64<RuntimeIdentifier> to the .csproj of my WebApi. Just answering here in case other people still getting the same error.

Guberniya answered 25/7, 2023 at 15:0 Comment(0)
R
-1

String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Microsoft.Data.SqlClient is not supported on this platform."

go to manage nugget packages and do a downgrade. Hope it works for you

Rilke answered 17/2, 2023 at 11:10 Comment(2)
"a downgrade" -- Downgrade what? From what to what? That said, why downgrade? An upgrade of the right package may just as well fix such issues.Met
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Dish
G
-1

I was able to resolve this issue by going into "Manage Nuget Packages" and updating the Microsoft.Data.SqlClient library to the latest version.

Giulietta answered 23/1, 2024 at 1:39 Comment(0)
F
-6

Change the framework to .NetCore 3.x or .NetFramework 4.x...

Flywheel answered 18/6, 2020 at 20:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.