MVC2 RC – Different assemblies? AddImplicitRequiredAttributeForValueTypes

I’ve been playing around with MVC2 looking to use it on a new project and was glad to see the release candidate was out.   Obviously if you’re looking to roll something out in the future you’re more confident using a RTM than a RC or a beta.  Beware though,MVC RC has been superseded by MVC2 RC2 and now MVC2 RTM.   You’ll have to uninstall MVC2 RC / RC2 if you want to install the RTM.  If you’re using the VS2010 RC  be wary you don’t uninstall MVC2 “Visual Studio 2010 tools” when you’re uninstalling MVC2.  If you do, your new MVC2 projects probably won’t load.   If you do uninstall the 2010 tools you can re-install them by uninstalling the Wed Development part of VS2010 and then re-install it via add/remove program components (mentioned on Phil Haack’s blog).

I’d been looking at Data Annotations and model validation and was really pleased to see how easy it was to get client-side validation up and running but the lack of supported attributes led me to look at JQuery Data Annotations as suggested by a colleague.

Again, great, this seemed to provide additional support.  I did encounter a problem though.   DataAnnotations was implementing a Required attribute on non-null data types automatically!!!!

Fortunately you can switch this behaviour off on the model validator provider.  The way to do this is to set the AddImplicitRequiredAttributeForValueTypes property to false.  I found this information on Jeremy Skinner’s blog post.

OK…nearly there….apart from the fact that DataAnnotationsModelValidatorProvider didn’t have an AddImplicitRequiredAttributeForValueTypes propery.

Digging a bit more I found a post that suggested that there was more than one version of the MVC2 RC out there.   I managed to get hold of another copy of System.Web.MVC from a colleague who had installed VS2010 RC.  He’d also installed MVC2 RC but wasn’t sure in which order.   The main thing was that it was different from the one in the MVC2 RC (as linked above).  It then became apparent that there was a new RC out there.

So…if you can’t set the AddImplicitRequiredAttributeForValueTypes propery because it doesn’t exist, check your dll version (System.Web.Mvc.dll).   2.0.41211.0 (356kb) was the version I originally had which came in the MVC2 RC download but this didn’t have the property.  2.0.50129.0 (365kb) did have the property, but this was in MVC2 RC2.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s