jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Upgrade from MVC4 to MVC5 breaks ExpressiveAnnotations? #137

Closed samgiordano closed 7 years ago

samgiordano commented 7 years ago

Hello,

I upgraded my project from MVC4 to MVC5 and I now receive the following error in my global.asax on this line:

DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredIfAttribute), typeof(RequiredIfValidator));

"The type ExpressiveAnnotations.MvcUnobtrusive.Validators.RequiredIfValidator must derive from System.Web.Mvc.ModelValidator"

When I change the entry in the global.asax to the method recommended in release 2.5:

ModelValidatorProviders.Providers.Remove(ModelValidatorProviders.Providers.FirstOrDefault(x => x is DataAnnotationsModelValidatorProvider)); ModelValidatorProviders.Providers.Add(new ExpressiveAnnotationsModelValidatorProvider());

I receive this error:

"An exception of type 'System.ArrayTypeMismatchException' occurred in mscorlib.dll but was not handled in user code Additional information: Attempted to access an element as a type incompatible with the array."

Thanks,

Steve

jwaliszko commented 7 years ago

When it comes to migration from MVC 4 to MVC 5 - I've done it, and it works. Maybe you've done some mistake during migration? I cannot verify it based on provided information.

Try to troubleshot that. Get some MVC 5 demo application, e.g. from Getting Started with ASP.NET MVC 5 (github link inside), and install EA. No such an error occurs.

(I assume you're not using ASP.NET Core since it is not supported yet.)

samgiordano commented 7 years ago

It is working now after I finished updating NuGet packages...most likely it was that EntityFramework needed to be updated to version 6 along with the MVC update.

Thank you.