FluentValidation: Could not load type 'FluentValidation.DependencyInjectionExtensions' after upgrading to latest version

FluentValidation version

12.0.0

ASP.NET version

9.0.5

Summary

I’m also receiving the same error as mentioned in #2314 with it all in one project rarther than seperate clean architecture style.

Program.cs has the following lines to load fluent validation

builder.Services.AddValidatorsFromAssemblyContaining<Program>();
builder.Services.AddFluentValidationAutoValidation(config =>
{
	config.DisableDataAnnotationsValidation = true;
});

builder.Services.AddFluentValidationClientsideAdapters();

the csproj has the following reference packages

    <PackageReference Include="FluentValidation" Version="12.0.0" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
    <PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />

downgrading it back to 11.11.0 resolves the error straight away

Steps to Reproduce

upgrade FluentValidation.DependencyInjectionExtension and FluentValidation packages to 12.0.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Ok I found the issue here and pushed out a 11.3.1 release of FluentValidation.AspNetCore with a fix.

Thanks for the reproduction @madhon. I’ve tested the fix with your sample project and confirmed it works correctly, but please give it a try to confirm.

@KirkMunroSagent this should sort the issue for you too.

There was a particular method being called that no longer exists in FV 12, my own test projects didn’t catch this due to how they were set up. A new testing target into FluentValidation.AspNetCore’s automated tests to now cover compatibility with FV 12.

the solution is to add an explicit, direct dependency to each project in the solution to the FluentValidation.DependencyInjectionExtensions 12.0.0 package, correct? That would make sense.

That’s correct

I’m going to need to look into the other newer package your docs mention, because I prefer auto-registration/invocation of the validators, but I don’t want to hold on to legacy, deprecated packages unless I have to and making the validation explicit/manual in each controller just isn’t what I want from validators in my code.

There’s no replacement for FluentValidation.AspNetCore and we recommend using manual validation within asp.net projects as the auto validation pipeline has too many limitations, which I’ve made several posts about (summarised here: https://github.com/FluentValidation/FluentValidation/issues/1960) but the package is still useable as a lot of people have dependencies on it so there’s no need to remove it if you are still relying on it. There are some third party alternatives that implement auto validation via an action filter instead of the validation pipeline which may be of interest too