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.
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.ValidatorAttributepackage.
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.ValidatorAttributepackage.- In legacy ASP.NET projects (MVC 5 and WebApi 2), the
ValidatorAttributeis still the default approach, and theFluentValidation.ValidatorAttributepackage will be automatically installed for compatibility. However, we recommend using an IoC container instead if you can.
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