11

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.

Mike Brind
  • 22,404
  • 6
  • 47
  • 77
Simon
  • 3,043
  • 1
  • 35
  • 66
  • Can you tell us what `dotnet --version` and `dotnet --list-sdks` output? We should see **3.1.300** ? Also please confirm what versions of the various AspNetCore Blazor references are, the should be `Version="3.2.0"` – Quango May 29 '20 at 09:55
  • 1
    I've just performed the setup of the same app. The WeatherForecast GET should be `content-type: application/json; charset=utf-8` whereas yours is `text/html` - I suspect it might be returning an error page. Try running `https://localhost:44325/WeatherForecast` directly in a browser? – Quango May 29 '20 at 09:59

2 Answers2

20

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

Simon
  • 3,043
  • 1
  • 35
  • 66
Mike Brind
  • 22,404
  • 6
  • 47
  • 77
1

Although this isn't true for the OP, who's getting a "200 Ok" response, this can also happen if your API method returns null (mine was throwing a DB exception and returning null as a fallback).

I had "204 No Content" as the response and "The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'." as the error at the client end.

I suppose null doesn't look like json :-)

Jon
  • 199
  • 2
  • 8