Closed alex-jitbit closed 2 years ago
@alex-jitbit this seems like duplication of #1390 and some other similar issues when using Kerberos authentication on Unix. Please check that issue thread.
@JRahnama nope, not using Kerberos auth, simply MS SQL user with password. This is a library/targeting/dependency issue, strictly
What is your Publish command?
@ErikEJ it's dotnet publish ..\path\to\MyProject.csproj --configuration Release -o path\to\OutputFolder
Once again, the same build works fine on Ubuntu, Windows Server etc. But some linux distros throw this error.
The System version of the library can only be updated as part of the runtime. The last runtime it shipped with was netcore 3.1. So regardless of the bug status I don't think it's going to get fixed in the System version.
Can you try with the Microsoft version of the library from this repo and see if it reproduces?
@alex-jitbit I will look into this, but as a wild guess could this be related/similar to #1249 and #81?
@JRahnama nope, I'm not using docker, it's a standalone SQL Server installation, accessed over network. And a standalone aspnetcore app (also - not in docker)
@Wraith2 just tried with Microsoft.Data.SqlClient
! SAME ERROR !
System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
: at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
The exception is trivially reproducible on WSL2: just install AlmaLinux 8
from MS Store and run any NET6 app. SqlConnection
constructor throws this error.
NET5 works fine. NET6 also works fine, but only on Ubuntu, not RHEL or its forks
Have you tried using the latest SDK?
@ErikEJ no, but I have tried installing dotnet as described in MS docs
Have you tried the steps to repro I provided?
I would try it with the latest .NET 6 servicing release first.
Yes 6.0.105 is not the latest SDK
@ErikEJ @AraHaan just updated to 6.06 and 6.0.106 - same exact error
UPD: sorry, just realized 106 is not the latest, will update and get back. Once I figure out how to update from MS package sources...
Latest is 6.0.301 I think - but it can be confusing
I have just installed the latest aspnetcore 6.0.6 runtime, which is the latest servicing release, and have the same exact error.
It really feels like you guys are just dragging the issue. Meanwhile almost a dozen of our customers are waiting for a fix.
P.S. do I really need the SDK installed to run apps though? Isn't the runtime enough? I spent an hour trying to find a way to install the "latest SDK" on RHEL/Alma/etc, and MS website does not describe any info. If you really want me to - please provide the instructions. https://docs.microsoft.com/en-us/dotnet/core/install/linux-rhel - is not very helpful.
I'm building a WM with nested virtualization enabled so I can setup all the stuff needed for wsl2 debugging. If it was a simple fix I wouldn't need to do that. So yes I imagine you're right that we're all dragging this out but it's because it's not a trivial thing to setup debugging for.
@Wraith2 appreciate
The source of the problem in the current code is AliasRegistryLookup
which is called from TdsParserStaticMethods.AliasRegistryLookup(ref host, ref protocol);
it uses the registry which throws a type initialization exception because it isn't supported on non-windows.
notice the comment and lack of try block.
Overall the lib is behaving as if it's running on windows, which is odd. have you tried a more mainstream liux?
Looks to me like it should be using the newer OperatingSystem class to guard against the call to the registry (which does not exist in linux unless running on wine).
I am surprised it does not throw on all unix OS’s.
If I guard that error I hit an error in SNIInitialize when it can't load the sni.dll file. That means that it's trying to use the windows implementation. The nuget restore shouldn't be be choosing that implementation. So it isn't that we're doing anything wrong in code at runtime only that the wrong implementation was chosen. I don't know exactly where that choice is made, or how. Cross platform isn't an area that I'm well versed in.
perhaps the issue is that they are not publishing it as FDD dependent but as rid specific as well (by using --self-contained false
).
Also I think having them skip the apphost as well to force usage of dotnet
here would be the way to go.
There's no deployment step at all. Both through wsl debugging and directly using dotnet run it uses the windows assembly. It shouldn't.
That is odd.
Any news regarding this issue? SqlClient is currently unusable on Linux.
It is usable under some Linux, just not the specific one that you want to use. We need to know why the nuget restore process isn't identifying your distro as Linux and that isn't something that is part of this library. You may need to open an issue on nuget and get their help.
@Wraith2 wow, OK thanks. Please let me know where should I transfer the issue for you.
Would be related to #1631.
When publishing a project depending on System.Data.SqlClient
on Linux with .NET 6.0.108, we seem to end up with the stub System.Data.SqlClient.dll
(which always throws the platform exception) and platform-specific artifacts in the runtimes
directory.
When then running the application using the .NET 6.0.8 runtime, for some reason, the stub System.Data.SqlClient.dll
is loaded at execution, whereas using .NET 6.0.0 loads runtimes/unix/lib/netcoreapp2.1/System.Data.SqlClient.dll
. It seems the issue is somewhere within the .NET runtime, not within SqlClient
itself.
EDIT: This is on Rocky Linux 8, for reference.
@Wraith2 Like you suggested I tried creating an issue with the nuget team, but they said the problem is with SqlClient, not nuget (see their response in the linked issue)
Again, to recap:
I'm getting this issue with PopOS 22 ( which is based on ubuntu I believe ). I specify the RID and it still appears. All my other code works fine except for this SqlClient package.
I have the same issue after updating to the latest version of PopOS 22.04:
System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform
Microsoft.Data.SqlClient is the latest version 5.0.0.
Here's my SDK and runtime versions:
6.0.108 [/usr/lib/dotnet/dotnet6-6.0.108/sdk]
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]
I got it working by doing the following (based on steps from here: https://github.com/dotnet/core/issues/7699)
sudo apt remove dotnet*
sudo apt remove aspnetcore*
sudo touch /etc/apt/preferences
Package: * Pin: origin "packages.microsoft.com" Pin-Priority: 1001
sudo apt install dotnet-sdk-6.0
This will install a newer SDK version (6.0.400 [/usr/share/dotnet/sdk]) which apparently solves this problem.
@alex-jitbit does the provided solution work for you?
@JRahnama I will run my tests and get back to you.
I believe the issue may be related to missing RIDs, such as for Rocky Linux, in the runtime. I've opened PR dotnet/runtime#74164 for Rocky Linux on the 6.0 servicing line.
I noticed that if I build .NET 6 project referencing System.Data.SqlClient
package on Windows, then System.Data.SqlClient.dll is copied to the bin folder which is a stub assembly where everything throws PlatformNotSupportedException
. At runtime the proper assembly is loaded from bin\runtimes
subfolder. Is that the expected behavior that bin contains stub assembly after build? Or a bug?
@Alex-Sob the part that the assembly is loaded from bin/runtimes is expected.
@JRahnama Yes, but my question is - does that make sense that after build bin folder contains stub assembly that contains only code throwing PlatformNotSupportedException
? Why not copy assembly for the current platform/architecture?
@Alex-Sob Because the stub assembly is the fallback in case the .NET runtime's RID inference logic fails, i.e. it doesn't find any specific runtime implementation of the assembly at hand. In the current state of things, there is a gap in .NET 6.0 in the sense that Rocky Linux (and I assume Alma as well) are not supported by the runtime identifier detection logic.
Effectively, depending on the platform, the .NET runtime may not be able to infer the OS to be either win-x64 or linux-x64 (which are the two implementations provided by System.Data.SqlClient
IIRC), and thus falls back on the stub implementation, which just throws platform not supported exceptions on every single method.
In other words, the gap is in the .NET runtime RID inference logic, not in SqlClient itself. I suspect other libraries which have the same stub+specific implementation structure will have the same problem.
I've submitted a PR to fill in the gap for Rocky Linux, but it probably needs to be done for other distributions such as Alma as well.
P.S. This mechanism is in fact what enables applications to be distributed while targeting several runtime platforms. You can of course override the RID during publishing (e.g. linux-x64), but in that case, the application will only run on that specific platform.
Anyone solved this on Pop!_OS 22.04?
EDIT: Solved installing the dotnet SDK manually and setting the path manually on Rider.
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-6.0.401-linux-x64-binaries
So I've been working on this problem for a little bit and here is what I've encountered
apt install dotnet6
causes the problem/usr/bin/dotnet
symbolic link path to that custom folder did resolve the problem... BUTExample
sudo ln -s /usr/lib/dotnet/custom/dotnet /usr/bin/dotnet
**Step 3 introduced a new bug/problem. I was able to get the application to startup and run but noticed that several of my EF Core queries stopped returning data. Even though the logged query should have returned something.
[EDIT] Upon further inspection my PC is set to EST and the date was suppose to be UTC and it made a conversion which is why the query returned different reuslts. This is likely my bug. Step 3 is the winner**
mcr.microsoft.com/dotnet/sdk:6.0-jammy
does work fine. Which confuses me because I am on the same version of Ubuntu (POP_OS!)Apparently this problem is affected by the value of RuntimeInformation.RuntimeIdentifier I ran into it by moving from Fedora 36 to Nobara 36 which is just Fedora with some modifications.
I went to /etc/os-release and changed ID from "nobara" to "fedora", which also changed RuntimeInformation.RuntimeIdentifier from "nobara.36-x64" to "fedora.36-x64" and everything worked again, so I guess it may be possible to fiddle with some of the values in this (or similar) file on other systems to make them fit into supported whitelist. I understand this can probably be dangerous and is not something anyone should normally do but maybe this information can be helpful to some people.
I tried looking into possibility of temporarily changing these values just to run dotnet and apparently on systems with lsb_release like Ubuntu it is possible to set path to os info with LSB_ETC_LSB_RELEASE variable but I don't see anything of the sort for Fedora/Red Hat. You can install lsb_release on Fedora but idk if this would change anything.
closing this as it's not an issue with the Microsoft.Data.SqlClient client package.
I was able to bypass this issue by putting all of EFCore (and Microsoft.Data.SqlClient) into generic linux-* rids and then manually installing them via extraction from tar.gz files into the $DOTNET_ROOT
this resulted in when I tried to run my discord bot in it working on all linux based OS's because I used the generic linux based RIDs for them (and it with r2r).
Also doing such bypass as an experiment also allowed me to be able to roll forward new updates to efcore to the discord bot without needing to rebuild which for me is a bonus because of servicing releases being considered critical for me (also the fact that rebuilding can be a nightmare).
Anyone solved this on Pop!_OS 22.04?
EDIT: Solved installing the dotnet SDK manually and setting the path manually on Rider.
https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-6.0.401-linux-x64-binaries
I managed to get it running using this workaround. Note: Frist I tried using the installer script dotnet-install.sh, but that didn't work. Simply downloading and extracting the binary manually worked fine.
closing this as it's not an issue with the Microsoft.Data.SqlClient client package.
Does anyone have a link to another bug report? I'm not sure I understand the problem correctly, and I can't find out where to go to follow up on this issue.
Have you tried using the latest SDK?
Yes I do But still facing the same Issue
Describe the bug
We have a cross platform ASP.NET 6.0 app (published as "portable") that runs fine on Windows, Ubuntu etc, but throws the above error on RHEL and AlmaLinux. Reverting to the older version of the app that targets .NET 5 works fine.
Both versions
System.Data.SqlClient 4.8.3
andMicrosoft.Data.SqlClient
throw this error. My connection-string uses an SQL user with a password, not using Kerberos or windows-integrated authentication.To reproduce
Create a .NET Core 6.0 app that references SqlClient, publish, deploy to RHEL, run with
dotnet MyProject.dll
THIS IS TRIVIALLY REPRODUCABLE on AlmaLinux 8 under WSL2 (available in MS Store). But it works fine under Ubuntu under WSL2.
Install WSL2, install Almalinux 8 from MS Store, run
sudo yum install dotnet-sdk-6.0 -y
to install dotnet, then run the app usingdotnet MyProject.dll
Almalinux dotnet--info output: