问题描述
我正在netcoreapp3.0
Web应用程序中使用netstandard2.1
库.在Startup
中添加我的服务时,出现以下错误:
I'm using netstandard2.1
library in my netcoreapp3.0
web application. When adding my service in Startup
, I'm getting the below error:
我还在类库中使用了Microsoft.AspNetCore.Mvc
2.2.0软件包中的某些功能.
I'm also using some features from Microsoft.AspNetCore.Mvc
2.2.0 package in my class library.
这是我的图书馆.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
</Project>
这是我图书馆中的ServiceExtensions
类,
public static class ServiceExtensions
{
public static IMvcBuilder AddMyLibrary(this IMvcBuilder builder)
{
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
builder.Services.ConfigureOptions<ConfigureLibraryOptions>();
return builder;
}
}
这是我的ConfigureLibraryOptions
课,
public class ConfigureLibraryOptions : IConfigureOptions<MvcOptions>
{
public void Configure(MvcOptions options)
{
options.ModelBinderProviders.Insert(0, new CustomBinderProvider());
}
}
这是Startup
中的ConfigureServices
,
services.AddControllersWithViews().AddMyLibrary();
请帮助我为什么会出现此错误,并帮助解决该问题?
Please help on why I'm getting this error and assist on how to solve this?
推荐答案
出现错误的原因是因为MvcJsonOptions
在.NET Core 3.0中已被删除.您可以在此处了解更多信息.
The reason you're getting the error is because MvcJsonOptions
was removed in .NET Core 3.0; you can read more about the breaking changes here.
这篇关于'无法从程序集'Microsoft.AspNetCore.Mvc.Formatters.Json,版本= 3.0.0.0中加载类型'Microsoft.AspNetCore.Mvc.MvcJsonOptions'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!