Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am having a problem to use to object with Fluentvalidation

I can not use the object in my code. It says cannot convert from object to FluentValidation.IvalidationContext.

namespace Northwind.Business.Utilities
{
    public static class ValidationTool
    {
        public static void Validate(IValidator validator, object entity)      
        {
            var result = validator.Validate(entity); 
            if (result.Errors.Count > 0)
            {
                throw new ValidationException(result.Errors);
            }
        }


    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The reason why you get the respective error is mentioned in Removal of non-generic Validate overload when you are upgrading to version 9.

You can resolve it by providing the IValidationContext instance.

var context = new ValidationContext<object>(model);
var result = validator.Validate(context); 

Otherwise, you shall consider migrating the validation to IValidator<T> with a generic type instead of IValidator.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading