Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dotnet Core 3.1 Upgrade error - Method 'GetValidationVisitor' does not have an implementation

I have upgraded WEB API dotnet core 2.2 project to 3.1.

inside the Startup.CS file I have the following method :

    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;
    }

Later I use this RegisterMvc() method inside ConfigureServices() to do the dependency injection.

After upgrading to the new dotnet core, I am getting the following error, and I am clueless about what it's trying to say or how to resolve it:

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.'
like image 996
Benjamin Avatar asked Dec 23 '19 10:12

Benjamin


1 Answers

The problem was automatically solved by upgrading the FluentValidation.AspNetCore to it's latest version.

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

like image 129
Benjamin Avatar answered Nov 11 '22 01:11

Benjamin