Dotnet Core 3.1 升级错误 - 方法“GetValidationVisitor”没有实现

Ben*_*min 6 c# .net-core asp.net-core

我已将 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;
    }
Run Code Online (Sandbox Code Playgroud)

后来我RegisterMvc()在里面用这个方法ConfigureServices()做依赖注入。

升级到新的 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.'
Run Code Online (Sandbox Code Playgroud)

Ben*_*min 9

问题是通过升级FluentValidation.AspNetCore到最新版本自动解决的。

https://www.nuget.org/packages/FluentValidation.AspNetCore/