Repository navigation
Closed
Description
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:
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"
Reacted by Rajib Bajracharya, Josh, Henrique Sousa, Alexander Yumashev, Christian Fosli and Evgeny Gorbovoy
Metadata
Metadata
Assignees
Labels
No labels

Activity
azuriteemporium commentedon Dec 7, 2021
A workaround seems to target the host platform directly, Linux x64 in this case

JRahnama commentedon Dec 7, 2021
@azuriteemporium thanks for bringing this up. Two questions:
Wraith2 commentedon Dec 7, 2021
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.
J05HM0N5TER commentedon Jan 4, 2022
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).
J05HM0N5TER commentedon Jan 4, 2022
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.
MolallaComm commentedon Apr 8, 2022
I ran into this on alma also - adding the
-r linux-x64flag to mydotnet runordotnet buildfixed it as @azuriteemporium pointed out. The funny thing is that on ubuntu 20.04 -dotnet runwithout the -r flag works fine.Cantaria commentedon Aug 28, 2022
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 updatei'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?
ErikEJ commentedon Aug 28, 2022
@Cantaria what SDK versions on computer A?
Cantaria commentedon Aug 28, 2022
Hi @ErikEJ
That are the ouputs from bash:
JRahnama commentedon Aug 29, 2022
@Cantaria I think Microsoft.EntityFrameworkCore.Design is needed as well.
ErikEJ commentedon Aug 29, 2022
@Cantaria I think you need a newer SDK
Cantaria commentedon Aug 29, 2022
@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.
ErikEJ commentedon Aug 29, 2022
@Cantaria is this related? dotnet/core#7699
Cantaria commentedon Aug 30, 2022
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-efIf i run it, i get the following output:
Maybe if it's help, the output from dotnet --info:
ErikEJ commentedon Aug 30, 2022
@Cantaria Please open a new issue in the EF Core repo, this seems very off topic here.
luanmm commentedon Sep 9, 2022
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 --infooutput) 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 forcinglinux-x64using 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.
Wraith2 commentedon Sep 9, 2022
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.
luanmm commentedon Sep 10, 2022
@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).
Wraith2 commentedon Sep 10, 2022
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.
luanmm commentedon Sep 10, 2022
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).
Wraith2 commentedon Sep 10, 2022
Until netcore 3.1 you could have been using
System.Data.SqlClientwhich was part of the runtime and did not need restoring so there was no problem with the RID. This library,Microsoft.Data.SqlClientis not part of the runtime and must be dealt with through package restore with a specific RID.luanmm commentedon Sep 11, 2022
I don't use this library directly. It is used, indirectly, by the
Microsoft.EntityFrameworkCore.SqlServerpackage. 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.
jacobschellenberg commentedon Oct 21, 2022
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:
.csproj
Please see my
dotnet --infooutput below: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))lcheunglci commentedon Oct 25, 2022
Hi @jacobschellenberg , I believe there was a solution suggested here that reinstalling the dotnet 6 and aspnetcore SDK resolved their issue.
lcheunglci commentedon Nov 1, 2022
Closing issue due to inactivity. Feel free to open new issue if this issue still exists.