Skip to content

Getting "System.PlatformNotSupportedException" in Blazor WebAssembly page. #599

@ghost

Description

Describe the bug

I tried to add and use the Microsoft.EntityFrameworkCore.SqlServer package in the Blazor WebAssembly page. However on loading the page component, it shows this exception and it is not able to run correctly.

If you are seeing an exception, include the full exceptions details (message and stack trace).

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

**Stack trace:**
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Microsoft.Data.SqlClient is not supported on this platform.
System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
  at Microsoft.Data.SqlClient.SqlConnection..ctor (System.String connectionString) [0x00006] in H:\tsaagent1\_work\9\s\obj\Release.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.notsupported.cs:295 
  at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection () <0x313e910 + 0x0000c> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection () <0x313e5c0 + 0x0003c> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand (Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject, System.Guid commandId, Microsoft.EntityFrameworkCore.Diagnostics.DbCommandMethod commandMethod) <0x3f20d30 + 0x000ec> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync (Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject, System.Threading.CancellationToken cancellationToken) <0x3f1f6b8 + 0x000ba> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1+AsyncEnumerator[T].InitializeReaderAsync (Microsoft.EntityFrameworkCore.DbContext _, System.Boolean result, System.Threading.CancellationToken cancellationToken) <0x3e91ae8 + 0x0014a> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult] (TState state, System.Func`4[T1,T2,T3,TResult] operation, System.Func`4[T1,T2,T3,TResult] verifySucceeded, System.Threading.CancellationToken cancellationToken) <0x3e90d20 + 0x000f4> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1+AsyncEnumerator[T].MoveNextAsync () <0x3e8a178 + 0x0050c> in <filename unknown>:0 
  at System.Threading.Tasks.ValueTask`1[TResult].get_Result () <0x3f715f0 + 0x00034> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource] (System.Linq.IQueryable`1[T] source, System.Threading.CancellationToken cancellationToken) <0x3486608 + 0x0015a> in <filename unknown>:0 
  at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource] (System.Linq.IQueryable`1[T] source, System.Threading.CancellationToken cancellationToken) <0x3486608 + 0x0025a> in <filename unknown>:0 
  at BlazorDemo1.Pages.Movies.OnInitializedAsync () [0x00122] in D:\Programs\WASM\BlazorDemo1\BlazorDemo1\Pages\Movies.razor:84 
  at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2f85ca0 + 0x0013a> in <filename unknown>:0 

To reproduce

Please try my test sample project here: https://github.com/mszixie/BlazorDemo1
The Sqlclient test page is the "/movies" page.
It's based on the default Blazor WebAssembly template.

Expected behavior

The SqlClient should be able to initialize and connect to my Azure SQL DB and retrieve data.

Further technical details

Microsoft.EntityFrameworkCore.SqlServer: 5.0.0-preview.5.20278.2 (or 3.1.5 doesn't work)
Microsoft.Data.SqlClient (dependency of Microsoft.EntityFrameworkCore.SqlServer) version: 2.0.0-preview3.20122.2. (or older version included in Microsoft.EntityFrameworkCore.SqlServer 3.1.5 doesn't work neither)
.NET target: .Net Standard 2.1 (It's default of Blazor WebAssembly)
Blazor WebAssembly: 3.2.0
SQL Server version: Azure SQL Database
VS: 16.6.2
Operating system: Windows 10 2004 64Bit

Additional context
I am inspired by the blog post here: https://blog.jeremylikness.com/blog/ef-core-and-cosmosdb-with-blazor-webassembly/
From this blog seems the EF Core Cosmos DB client supports Blazor WebAssembly now, so I wonder if SqlClient in EF Core also supports this new platform. However, in my test I am getting the above error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    External 🔗Issue is in an external component

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions