Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor WebAssembly: The provided ContentType is not supported;

I have installed the Blazor WebAssembly Example Project (WeatherForecast) today by the following command line:

dotnet new blazorwasm --hosted -o ProjectName

I started the SPA directly after the installation via Visual Studio 2019 in Debug Mode. The Browser is: Chrome. The Browser shows the app, but when I select the Nav Menu "Fetch Data" then nothing happens. Chrome shows 1 Error:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
System.NotSupportedException: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
  at System.Net.Http.Json.HttpContentJsonExtensions.ValidateContent (System.Net.Http.HttpContent content) <0x2e87f38 + 0x0009a> in <filename unknown>:0 
  at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync[T] (System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e87d30 + 0x00006> in <filename unknown>:0 
  at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsyncCore[T] (System.Threading.Tasks.Task`1[TResult] taskResponse, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e40838 + 0x0011c> in <filename unknown>:0 
  at BlazorIssue.Client.Pages.FetchData.OnInitializedAsync () [0x00033] in D:\Projects\BlazorIssue\Client\Pages\FetchData.razor:43 
  at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2b8cb98 + 0x0013a> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2dd8340 + 0x000b6> in <filename unknown>:0 

Chrome shows the following Request Headers:

Blazor WebAssembly Request Headers

Context-Information:

  • Chrome: V83.0.4103.61 (64bit)
  • Blazor: V3.2.0
  • Visual Studio: V16.6.0
  • DotNet V3.1.300
  • DotNet SDK: V3.1.300

That is curious because a fresh installation of this example project worked yesterday with no problems.

like image 781
Simon Avatar asked May 29 '20 08:05

Simon


People also ask

How do I add authentication to Blazor WebAssembly?

To create a new Blazor WebAssembly project with an authentication mechanism: After choosing the Blazor WebAssembly App template in the Create a new ASP.NET Core Web Application dialog, select Change under Authentication. Select Individual User Accounts to use ASP.NET Core's Identity system.

Why Blazor is not popular?

Blazor projects are slow on the client-side because you have to download the entire dot net runtime along with the necessary DLL libraries on your browser. Additionally, Blazor apps have latency issues.

How do I get the current URL in Blazor WebAssembly?

Inject NavigationManager in razor. Use Uri from NavigationManager to get the current URL.


1 Answers

This can happen in the ASP.NET Hosted version of the Web Assembly template project if the Client project is designated as the Startup project. Ensure that the Server project is set as the Startup project.

Blazor WebAssembly - Server - Startup Project

like image 51
Mike Brind Avatar answered Sep 22 '22 18:09

Mike Brind