Skip to content

[net 6.0] [linux] Microsoft.Data.SqlClient is not supported on this platform #1423

Closed

Description

@azuriteemporium

Describe the bug

Deploying a net 6.0 application on Linux trying to connect to a MS SQL server fails with the following exceptions when the 'Portable' runtime is selected during the build/publish step:

image

rkCore.SqlServer:6.0.0' with options: None
Unhandled exception. System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platfo
rm.
   at Microsoft.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.<>c.<get_IsMultipleActiveResultS
etsEnabled>b__7_0(String cs)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) in /builddir/bui
ld/BUILD/dotnet-9e8b04bbff820c93c142f99a507a46b976f5c14c/src/runtime.4822e3c3aa77eb82b2fb33c9321f923cf11ddde6/artif
acts/source-build/self/src/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/Concurrent
Dictionary.cs:line 1161
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.get_IsMultipleActiveResultSetsEn
abled()
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerCompiledQueryCacheKeyGenerator.GenerateCacheK
ey(Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnu
merator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) in /builddir/build/BUILD/dotnet-9e8b04bbff8
20c93c142f99a507a46b976f5c14c/src/runtime.4822e3c3aa77eb82b2fb33c9321f923cf11ddde6/artifacts/source-build/self/src/
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs:line 83
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) in /builddir/build/BUILD/dotnet-9e8b04bbff820c93
c142f99a507a46b976f5c14c/src/runtime.4822e3c3aa77eb82b2fb33c9321f923cf11ddde6/artifacts/source-build/self/src/src/l
ibraries/System.Linq/src/System/Linq/ToCollection.cs:line 29

Further technical details

Microsoft.Data.SqlClient version: 4.0 and 2.0

Linux x64 OS details:

NAME="AlmaLinux"
VERSION="8.5 (Arctic Sphynx)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.5"
PLATFORM_ID="platform:el8"
PRETTY_NAME="AlmaLinux 8.5 (Arctic Sphynx)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:almalinux:almalinux:8::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-8"
ALMALINUX_MANTISBT_PROJECT_VERSION="8.5"

Activity

  1. azuriteemporium commented on Dec 7, 2021

    @azuriteemporium
    Author

    A workaround seems to target the host platform directly, Linux x64 in this case
    image

  2. JRahnama commented on Dec 7, 2021

    @JRahnama
    Contributor

    @azuriteemporium thanks for bringing this up. Two questions:

    1. have you tested with net5?
    2. have you tried to address/change runtimes from Unix folder of the nuget
  3. Wraith2 commented on Dec 7, 2021

    @Wraith2
    Contributor

    The nuget contains implementations in the /runtimes folder for win and unix, if you restore using portable there is no way to pick up a real runtime specific implementation so you'll get the smaller assembly stub which just throws pnse exceptions for everything.

    In theory the unix (fully managed) implementation could be made the default so it would always work but there are perf and behaviour differences that people would then complain about.

  4. J05HM0N5TER commented on Jan 4, 2022

    @J05HM0N5TER

    I had/have this problem as well (with me, it was with local development on Linux). I managed to work around it by copying everything in ~/.nuget/packages/system.data.sqlclient/4.8.3/runtimes/unix/lib/netcoreapp2.1/ into [Project path]/bin/Debug/net6.0/bin/. My system is running Manjaro x64.

    EDIT: This only helped get a bit further in the process (a couple of lines of code, it let me sign in with managed identities), but then I encountered the same error. This is now completely stopping me developing, trying other versions of the package didn't do anything (I couldn't go back far because I had a dependency on something fairly new).

  5. J05HM0N5TER commented on Jan 4, 2022

    @J05HM0N5TER

    I just tried running in an Ubuntu docker container, and it worked. I don't know if this is to do with Ubuntu or a fresh OS (docker container) but some part of that fixed it.

  6. MolallaComm commented on Apr 8, 2022

    @MolallaComm

    I ran into this on alma also - adding the -r linux-x64 flag to my dotnet run or dotnet build fixed it as @azuriteemporium pointed out. The funny thing is that on ubuntu 20.04 - dotnet run without the -r flag works fine.

  7. Cantaria commented on Aug 28, 2022

    @Cantaria

    I've 2 computers which i use to develop.

    Computer A is a freshly installed Linux Mint Vanessa and installed .Net 6.0.8 (runtime + SDK) with installed Entity-Framework Tools 6.0.8:
    If i run dotnet ef database update i'm getting the System.PlatformNotSupportedException.
    Adding Migration worked fine.

    Computer B is an updated system from Ubuntu 20.04 to Ubuntu 22.04. It also has updated Net 5.0.11 to Net 6.0.8 (runtime+sdk) with installed Entity-Framework Tools 5.0.11
    If i run dotnet ef database update, everything works.
    Adding Migration worked fine.

    If i downgrade the EF-Tool an computer A to the same version as Computer B: still does not work

    Do i need an additional NuGet package for the "dotnet ef"-commands?

  8. ErikEJ commented on Aug 28, 2022

    @ErikEJ
    Contributor

    @Cantaria what SDK versions on computer A?

  9. Cantaria commented on Aug 28, 2022

    @Cantaria

    Hi @ErikEJ

    That are the ouputs from bash:

    clemens@MasterPC:~$ dotnet --list-sdks
    6.0.108 [/usr/lib/dotnet/dotnet6-6.0.108/sdk]
    clemens@MasterPC:~$ dotnet --list-runtimes
    Microsoft.AspNetCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 6.0.8 [/usr/lib/dotnet/dotnet6-6.0.108/shared/Microsoft.NETCore.App]
    
  10. JRahnama commented on Aug 29, 2022

    @JRahnama
    Contributor
  11. ErikEJ commented on Aug 29, 2022

    @ErikEJ
    Contributor

    @Cantaria I think you need a newer SDK

  12. Cantaria commented on Aug 29, 2022

    @Cantaria

    @ErikEJ this is the newest version i'm getting from the ubuntu repositories. :(
    After the Update to 22.04 i've had to disable to Microsoft-repositories due conflicts.

    image

  13. ErikEJ commented on Aug 29, 2022

    @ErikEJ
    Contributor

    @Cantaria is this related? dotnet/core#7699

  14. Cantaria commented on Aug 30, 2022

    @Cantaria

    Hi @ErikEJ ,

    i have now installed the dotnet from the PMC like in the link. It seems that everything has worked (now i have version 6.0.400)

    I can build and run my App, but i can't run dotnet ef database update

    I've installed dotnet ef with
    dotnet tool install --global dotnet-ef

    If i run it, i get the following output:

    clemens@MasterPC:~/Dev/Projects/Riddle/X3Code.Riddle./X3Code.Riddle.Database$ dotnet ef database update --startup-project ../X3Code.Riddle.WebService 
    You must install .NET to run this application.
    
    App: /home/clemens/.dotnet/tools/dotnet-ef
    Architecture: x64
    App host version: 6.0.8
    .NET location: Not found
    
    Learn about runtime installation:
    https://aka.ms/dotnet/app-launch-failed
    
    Download the .NET runtime:
    https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linuxmint.21-x64&apphost_version=6.0.8
    

    Maybe if it's help, the output from dotnet --info:

    clemens@MasterPC:~$ dotnet --info
    .NET SDK (reflecting any global.json):
     Version:   6.0.400
     Commit:    7771abd614
    
    Laufzeitumgebung:
     OS Name:     linuxmint
     OS Version:  21
     OS Platform: Linux
     RID:         linux-x64
     Base Path:   /usr/share/dotnet/sdk/6.0.400/
    
    global.json file:
      Not found
    
    Host:
      Version:      6.0.8
      Architecture: x64
      Commit:       55fb7ef977
    
    .NET SDKs installed:
      6.0.400 [/usr/share/dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    
    Download .NET:
      https://aka.ms/dotnet-download
    
    Learn about .NET Runtimes and SDKs:
      https://aka.ms/dotnet/runtimes-sdk-info
    
    
  15. ErikEJ commented on Aug 30, 2022

    @ErikEJ
    Contributor

    @Cantaria Please open a new issue in the EF Core repo, this seems very off topic here.

  16. luanmm commented on Sep 9, 2022

    @luanmm

    @Cantaria Please open a new issue in the EF Core repo, this seems very off topic here.

    People in EF Core repo says its not a problem in its side. People in SqlClient repo says it is. Definately there is a problem loading some libs here or in EF Core.

    A clue (maybe) from my side: in the latest versions of .NET SDK, the runtime identifier of the global binary was stated (in dotnet --info output) as "ubuntu.22.04-x64" in my environment. My guess is that SqlClient (or EF Core, but IMHO is something wrong with SqlClient) is not recognizing this identifier and throwing this error. That explains why a more generic runtime identifier (like when forcing linux-x64 using the tools) works.

    It's been a pain to work with SQL Server that way. Please don't close this issue like the others regarding this subject.

  17. Wraith2 commented on Sep 9, 2022

    @Wraith2
    Contributor

    SqlClient relies on package restore process to identify the correct binary to include in the output directory. If you get the wrong version then things won't work. The fact that there are separate per-system binaries is unfortunate but is not going to change any time soon. I understand that people want it to "just work" but there isn't really anything that can be changed in this library to fix the issue. Where the problem is and who needs to fix it I can't tell you.

  18. luanmm commented on Sep 10, 2022

    @luanmm

    @Wraith2 thanks for the clarification. Could you please give any clue on where to report this error, then? Maybe its not even an EF Core or SqlClient error, but it should be reported to a team that can work on it (now or in the future). I really don't know the deeper mechanisms of the libraries to have this answer.

    Today, this kind of thing pushes me away from SQL Server (the need to manually specify the runtime is not a solution, is just a poor workaround).

  19. Wraith2 commented on Sep 10, 2022

    @Wraith2
    Contributor

    he need to manually specify the runtime is not a solution, is just a poor workaround

    You always have to do this, and always have had to on netcore. This is not new. The netfx version was windows only so it always just worked.

    As for who to report it to I don't know. If possible I'd say open a support issue then there is some form of SLA attached to it.

  20. luanmm commented on Sep 10, 2022

    @luanmm

    You always have to do this, and always have had to on netcore. This is not new. The netfx version was windows only so it always just worked.

    I'm very sure this wasn't a requirement (for my project) until newer .NET (Core) versions (that's why I'm insisting in bring here the runtime identifier point). I always ran the very same projects in Windows and Linux without any problem. This "not supported" thing is an issue that has occurred in the last weeks.

    I'm currently working in a project that uses SQL Server and is developed by a "multi-platform dev team", which has diversity of platforms for development (Windows, Linux, Mac, ...) and the very same project was working until some environment updates. This project never had anything specified in terms of runtime/platform. But now it is giving this error when calling SQL Server functions from EF Core.

    I'm very sure it is related to some behavior change in .NET platform or SQL Server related libraries and is something that was not occurring in the past (at least in Ubuntu).

  21. Wraith2 commented on Sep 10, 2022

    @Wraith2
    Contributor

    Until netcore 3.1 you could have been using System.Data.SqlClient which was part of the runtime and did not need restoring so there was no problem with the RID. This library, Microsoft.Data.SqlClient is not part of the runtime and must be dealt with through package restore with a specific RID.

  22. luanmm commented on Sep 11, 2022

    @luanmm

    I don't use this library directly. It is used, indirectly, by the Microsoft.EntityFrameworkCore.SqlServer package. And, I insist, the runtime identifier was never explicitly configured (it's not a common practice to specify it in .NET applications as could be with libraries, thinking in a native interop point of view). The project that I'm referring to is using .NET 6 since the beginning, so this couldn't be what started causing this problem.

    I think that it could be caused by some change in the SDK itself. But is not clear why. No other library stopped working like SqlClient did.

  23. jacobschellenberg commented on Oct 21, 2022

    @jacobschellenberg

    Hello,

    I am working with WebAPI on Linux Mint and ran into this PlatformNotSupported issue. I see this ticket is still open, so I figured I'd add my experience to it. I originally had PopOS installed on this machine working with the exact same codebase and it worked just fine. However now I am on Linux Mint, and suddenly I have this error.

    The exact error is:

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

    .csproj

    <Project Sdk="Microsoft.NET.Sdk">
    ...
        <TargetFramework>net6.0</TargetFramework>
    ...
        <PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
    
    

    Please see my dotnet --info output below:

    .NET SDK (reflecting any global.json):
     Version:   6.0.110
     Commit:    ce0a42998a
    
    Runtime Environment:
     OS Name:     linuxmint
     OS Version:  21
     OS Platform: Linux
     RID:         ubuntu.22.04-x64
     Base Path:   /usr/lib/dotnet/dotnet6-6.0.110/sdk/6.0.110/
    
    global.json file:
      Not found
    
    Host:
      Version:      6.0.10
      Architecture: x64
      Commit:       5a400c212a
    
    .NET SDKs installed:
      6.0.110 [/usr/lib/dotnet/dotnet6-6.0.110/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 6.0.10 [/usr/lib/dotnet/dotnet6-6.0.110/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 6.0.10 [/usr/lib/dotnet/dotnet6-6.0.110/shared/Microsoft.NETCore.App]
    
    

    Please let me know if there is any other information I can give to help resolve this issue for Linux Mint.

    Thank you.


    EDIT:
    I've been able to resolve my own issue, which may be separate from others are dealing with.
    I was originally using a SQL database, but migrated to SQLite. Turns out you need to use the SQLite connection class and not the Microsoft/System.Data.Sql class.

    I added this package to my project, and updated the connection class.
    https://www.nuget.org/packages/System.Data.SQLite.Core
    using (var connection = new SQLiteConnection(connectionString))

  24. lcheunglci commented on Oct 25, 2022

    @lcheunglci
    Contributor

    Hi @jacobschellenberg , I believe there was a solution suggested here that reinstalling the dotnet 6 and aspnetcore SDK resolved their issue.

  25. lcheunglci commented on Nov 1, 2022

    @lcheunglci
    Contributor

    Closing issue due to inactivity. Feel free to open new issue if this issue still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions