【发布时间】:2020-04-14 15:12:05
【问题描述】:
我已将 WEB API dotnet core 2.2 项目升级到 3.1。
在Startup.CS 文件中,我有以下方法:
public static IServiceCollection RegisterMvc(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
{
try
{
services
.AddMvc(options =>
{
options.Filters.Add(typeof(ValidationActionFilter));
})
.AddControllersAsServices()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
})
.AddFluentValidation(fv =>
{
fv.ImplicitlyValidateChildProperties = true;
fv.RegisterValidatorsFromAssemblyContaining<MyValidationClass>();
});
}
catch (ReflectionTypeLoadException ex)
{
foreach (Exception inner in ex.LoaderExceptions)
{
Console.WriteLine(inner.Message);
}
throw ex;
}
return services;
}
稍后我在ConfigureServices() 中使用这个RegisterMvc() 方法来进行依赖注入。
升级到新的 dotnet 核心后,我收到以下错误,我不知道它想说什么或如何解决它:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Method 'GetValidationVisitor' in type
'FluentValidation.AspNetCore.FluentValidationObjectModelValidator' from assembly
'FluentValidation.AspNetCore, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
does not have an implementation.'
【问题讨论】:
-
可能是一些 NuGet 包问题,你能在包管理器中检查合并包吗?
-
您是如何注册您的
RegisterMvc的?您的GetValidationVisitor是什么?您能否调试一下出现此错误的行并提供一个可以重现您的问题的简单演示?
标签: c# asp.net-core .net-core