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.'
The problem was automatically solved by upgrading the FluentValidation.AspNetCore
to it's latest version.
https://www.nuget.org/packages/FluentValidation.AspNetCore/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With