question

SawomirPiotrowski-9117 avatar image
0 Votes"
SawomirPiotrowski-9117 asked SawomirPiotrowski-9117 answered

asp.net core 5 application and microsoft.data.sqlclient

Hello,

I'm working on an asp.net core 5 application.

Trying to use Microsoft.Data.SqlClient on development machine and it works, but after installing on test server the result is like that:

An error occurred while starting the application.
PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
Microsoft.Data.SqlClient.SqlConnection..ctor(string connectionString)
PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
Microsoft.Data.SqlClient.SqlConnection..ctor(string connectionString)
TelsatRcpAccess.Startup.CreateDatabaseIfItsNotThere(string OriginalConnectionString) in Startup.cs

Where should I search for source of the problem?

Current content of 'dependencies / packages':
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (5.0.4)
Microsoft.AspNetCore.Identity.EntityFrameworkCore (5.0.4)
Microsoft.AspNetCore.Identity.UI (5.0.4)
Microsoft.Data.SqlClient (2.0.1)
Microsoft.EntityFrameworkCore.SqlServer (5.0.4)
Microsoft.EntityFrameworkCore.Tools (5.0.4)
Microsoft.Extensions.Caching.SqlServer (5.0.1)
Microsoft.VisualStudio.SlowCheetah (3.2.26)

The fact that it works on development machine suggests that problem is with lack of installing something required by sqlclient.
I am installing .net framework 4.8 and .net core 5 before installing test application.
Test server is Windows Server 2019 with IIS and SQL Server 2019.

dotnet-aspnet-core-general
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The problem is NOT caused by my usage of SqlClient. If I skip database creation code and create database by SSMS than similar error is caused later by Sql cache access code (again, it works on development machine).

Trace:
PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
Microsoft.Data.SqlClient.SqlConnection..ctor(string connectionString)
Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(string key, bool includeValue, CancellationToken token)
Microsoft.Extensions.Caching.SqlServer.DatabaseOperations.GetCacheItemAsync(string key, CancellationToken token)
Microsoft.Extensions.Caching.SqlServer.SqlServerCache.GetAsync(string key, CancellationToken token)
Microsoft.Extensions.Caching.Distributed.DistributedCacheExtensions.GetStringAsync(IDistributedCache cache, string key, CancellationToken token)
TelsatRcpAccess.Models.WorkerStateCache.GetWorkerWorkState(Guid Worker, string LoginName) in WorkerStateCache.cs

0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered SawomirPiotrowski-9117 published

@SawomirPiotrowski-9117

Your development machine is running what O/S? What O/S is MS SQL Server hosted on in this situation, and what version of MS SQL Server is being used?

On the flip-side, what is the same information asked above when the solution is deployed?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

My development machine is Windows 10 64-bit with SQL Server 2019 Developer (the same version of SQL Server as on test deployment virtual machine). Development machine has visual studio and a lot of other software (including other .net versions). On both machines SQL Server is used locally (trivial connection string: "DefaultConnection": "Server=.;Database=(mydbname);Trusted_Connection=True;MultipleActiveResultSets=true". I have double checked that SQL has access rights granted for user IIS APPPOOL\DefaultAppPool. I have also tried to launch DefaultAppPool (in IIS) as local service. No changes. But I'd expect an error message if SQL said I had no rights should be different.

I have also added in SQL 'client tools backwards compatibility', just in case. Using newest .net I'd expect I wouldn't need backwards compatilibity, but tried that too. No changes.

0 Votes 0 ·
cheong00 avatar image
1 Vote"
cheong00 answered cheong00 edited

What is your usage?

From their source code, seems the only cause that would raise PlatformNotSupportedException with default error message on Windows is when with enclave attestation (more information here)

If the Application is UAP but it's trying to create LocalDB connection, it will have custom error message to explicitly state that; and I assume you don't use SqlFileStream which will also raise with custom error message to tell you exactly what happened.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SawomirPiotrowski-9117 avatar image
0 Votes"
SawomirPiotrowski-9117 answered

Looks like the source of the problem is... setup project.

My setup project (generated by Visual Studio extension) doesn't install applicationname.deps.json file. I have copied that file by hand and it works now. Should be able to add the file manually from publish folder on my development machine (the file is copied when publish function is used), but still wonder why wasn't it included automatically in setup.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.