SqlClient: [net 6.0] [linux] Microsoft.Data.SqlClient is not supported on this platform
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"
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 25 (12 by maintainers)
I ran into this on alma also - adding the
-r linux-x64
flag to mydotnet run
ordotnet build
fixed it as @azuriteemporium pointed out. The funny thing is that on ubuntu 20.04 -dotnet run
without the -r flag works fine.A workaround seems to target the host platform directly, Linux x64 in this case
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.
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.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).