Blazor WebAssembly:不支持所提供的ContentType;

问题描述 投票:0回答:1

我今天通过以下命令行安装了Blazor WebAssembly示例项目(WeatherForecast):

dotnet new blazorwasm --hosted -o ProjectName

我在调试模式下通过Visual Studio 2019安装后启动了SPA透明性。浏览器是:Chrome。但是,当我选择导航菜单“获取数据”时,浏览器会显示该应用程序,但是什么也没有发生。 Chrome显示1错误:

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显示以下请求标题:

Blazor WebAssembly Request Headers

上下文信息:-Chrome:V83.0.4103.61(64位)-Blazor:V3.2.0-Visual Studio:V16.6.0-点网V3.1.300-DotNet SDK:V3.1.300

这很好奇,因为该示例项目的全新安装昨天运行正常,没有问题。

asp.net asp.net-web-api blazor blazor-client-side blazor-webassembly
1个回答
0
投票

如果将客户端项目指定为启动项目,则在Web程序集模板项目的ASP.NET托管版本中可能会发生。确保将Server项目设置为Startup项目。

© www.soinside.com 2019 - 2024. All rights reserved.