Skip to content

Regression with published application: PlatformNotSupportedException #445

@davedx

Description

@davedx

Describe the bug

We have a .NET core application that is built and published inside a dockerfile. When we upgraded EF core to 3.1 and deployed our app, it started crashing at runtime in the SqlClient constructor with a PlatformNotSupportedException. After some investigation we determined the issue is related to how SqlClient is deployed with dotnet publish; also upgrading only SqlClient in isolation would result in the same crash. Running a shell inside the docker image it appears the correct SqlClient DLL for the platform (Linux) is not copied to the root of the application.

One workaround is to remove the --runtime linux-x64 flag from dotnet publish. Then it works. But this produces a different type of build (not self contained).

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

Stack trace:   
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source)
   at EFGetStarted.Program.Main(String[] args) in /src/Program.cs:line 14

To reproduce

Clone this repo: https://github.com/davedx/sqlclient-repro

Then run:

docker build -t efgs -f ./Dockerfile.custom.dotnet.3.1 .

docker run efgs

Expected behavior

Previous to upgrading SqlClient, this dockerfile and deploy process worked and app would run without crashing.

Further technical details

Microsoft.Data.SqlClient version: 1.0.19269.1
.NET target: (Core 3.1)
SQL Server version: (SQL Server 2019)
Operating system: (Docker container)

Additional context

There seems to be a related issue here: dotnet/runtime#29522

But we are on a newer version of dotnet core than the version in the above issue that fixed the issue. I'm happy to also open an issue no that repo if you think it's an issue with a different component but thought I had to start somewhere. :)

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