dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.56k stars 4.54k forks source link

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

Open xs2bharat opened 3 weeks ago

xs2bharat commented 3 weeks ago

Describe the bug

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

Exception message:System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
Stack trace: System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
   at Microsoft.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)

To reproduce

Use Microsoft.Data.SqlClient" Version="5.2.1" in mcr.microsoft.com/dotnet/aspnet:6.0.28-alpine3.19 image "ConnectionString": "Server=tcp:xxxxxxx.database.windows.net;Initial Catalog=XXXXXXX;Connection Timeout=50"

var sqlConnectionBuilder = new SqlConnectionStringBuilder(this.connectionString)
{
    UserID = this.settings.DatabaseUsername,
    Password = this.databasePassword
};

Expected behavior

Successful connection should be created

Further technical details

Microsoft.Data.SqlClient version: 5.2.1 .NET target: net6.0 SQL Server version: Azure SQL Database Managed Instance, Windows Server 2022 Datacenter (10.0) Operating system: Docker container - mcr.microsoft.com/dotnet/aspnet:6.0.28-alpine3.19

Additional context Add any other context about the problem here.

dauinsight commented 3 weeks ago

Can you confirm if this occurs on other versions of SqlClient?

Can you also try explicitly setting the runtime id as discussed in this thread: https://github.com/dotnet/SqlClient/issues/2030#issuecomment-1946205214

xs2bharat commented 3 weeks ago

Issue is fixed when switched to docker image mcr.microsoft.com/dotnet/aspnet:6.0.28-alpine3.18

kf-gonzalez2 commented 2 weeks ago

It might be an issue in the .Net platform detection logic not detecting alpine 3.19 as linux.

dotnet-policy-service[bot] commented 2 weeks ago

Tagging subscribers to this area: @davoudeshtehari, @david-engel, @jrahnama See info in area-owners.md if you want to be subscribed.

ErikEJ commented 2 weeks ago

Maybe https://github.com/dotnet/dotnet-docker/issues/5243 is related?