考虑我的项目文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="3.0.0-preview4-19123-01" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview5-19227-01" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
我的Startup.cs
:
public void ConfigureServices(IServiceCollection services)
{
[..]
services.
AddMvc().
AddNewtonsoftJson(); // Here is the problem
}
每当我尝试加载NewonsoftJson格式化程序时,在运行API时都会得到以下视图:
TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter' from assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
我应该如何解释,为什么格式化程序不在预期的位置?甚至在寻找正确的格式化程序吗?
答案 0 :(得分:0)
我也遇到了此错误,但是使用
services.AddMvcCore().AddNewtonsoftJson();
目前正在dotnet core 3.0预览版5中运行