question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression with published application: PlatformNotSupportedException

See original GitHub issue

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: https://github.com/dotnet/runtime/issues/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. 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
davedxcommented, Mar 3, 2020

Hi @cheenamalhotra,

Thanks a lot for following up on this issue, it’s appreciated. I confirm this is caused by the sdk’s behaviour and it’s not sqlclient’s fault 😃 Maybe it would be nice to add a line about this to the FAQ entry for PlatformNotSupported Exception to help future travellers. Have a good week.

0reactions
cheenamalhotracommented, Mar 3, 2020

Hi @davedx

As per comment https://github.com/dotnet/runtime/issues/33046#issuecomment-593714200 this behavior is by design. Let me know for any more questions you have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "PlatformNotSupportedException" in .NETCore 3.1 ...
I am working on multiplatform library which uses System.IO.Ports. Library is written in .NET Core 3.1 and uses System.IO.Ports 4.7 from Nuget, ...
Read more >
Incorrect output is returned when you use the Linear ...
Discusses a problem in which the incorrect output is returned when you use Linear Regression (LINEST) function in Excel.
Read more >
Understanding Diagnostic Plots for Linear Regression Analysis
After running a regression analysis, you should check if the model works well for the data. We can check if a model works...
Read more >
Bayesian multivariate linear regression with application to ...
The approach allows simultaneous single change point detection in a multivariate sample and can account for missing data in the response ...
Read more >
A Refresher on Regression Analysis
This is called the “regression line,” and it's drawn (using a statistics program like SPSS or STATA or even Excel) to show the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found