Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load type "FluentValidation.Attributes.ValidatorAttribute"

System.TypeLoadException: 'Could not load type 'FluentValidation.Attributes.ValidatorAttribute' from assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'.'

I am getting the above error after upgrade from .netcore2 to .netcore6.I tried upgrading to the latest 10.x but in vain. Also, there is no Nuget for verson 9.0.0 as thrown in the error, only 9.0.1 is availble and that also throws the same error.

like image 349
Arun Prakash Nagendran Avatar asked Nov 28 '25 02:11

Arun Prakash Nagendran


1 Answers

Starting from FluentValidation version 8.0 that ValidatorAttribute has been moved to a separate NuGet package FluentValidation.ValidatorAttribute.

From the documentation

Use of the ValidatorAttribute to wire up validators is no longer recommended and have been moved to a separate FluentValidation.ValidatorAttribute package.

Note that using that attribute is not recommended anymore, and is even considered legacy.
For that reason that NuGet package has the below notice.

This package has been deprecated as it is legacy and is no longer maintained.

The documentation shows how to migrate

  • In ASP.NET Core projects, you should use the service provider to wire models to their validators (this has been the default behaviour for ASP.NET Core projects since FluentValidation 7)
  • For desktop or mobile applications, we recommend using an IoC container to wire up validators, although you can still use the attribute approach by explicitly installing the FluentValidation.ValidatorAttribute package.
  • In legacy ASP.NET projects (MVC 5 and WebApi 2), the ValidatorAttribute is still the default approach, and the FluentValidation.ValidatorAttribute package will be automatically installed for compatibility. However, we recommend using an IoC container instead if you can.
like image 111
pfx Avatar answered Nov 29 '25 14:11

pfx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!