MVC.NET 2 Breaking Changes

Breaking changes in MVC.NET 2 (aka ASP.NET MVC 2):

  • There is a change to the behaviour of the Model Binder.  In MVC.NET 1, when a string property had no value to be bound to it, the Model Binder would assign an empty string to the property.  In MVC.NET 2 the model binder will assign null instead.  This can cause many issues.  See http://brianreiter.org/2010/09/16/asp-net-mvc-2-0-undocumented-model-string-property-breaking-change/ for more info.  I’d recommend getting used to the new MVC.NET 2 behaviour instead of using ModelBinders.Binders.DefaultBinder to go back to the MVC.NET 1 behaviour.
  • By default you can no longer return JSON from an Action that accepts HTTP GETs.  This is with good reason and closes up some serious potential security holes.  If you understand the implications, you can bypass this restriction on a case-by-case basis using the new overload of the Json method: http://msdn.microsoft.com/en-us/library/ee430920.aspx

Assembly Version, Assembly File Version and Assembly Informational Version

.NET provides three assembly-level attributes for adding a version number to your .NET assembly:

[assembly: AssemblyVersionAttribute("1.0.0.0")]
[assembly: AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]

For the last few years I’ve often left the Assembly Version set to a fixed value (e.g. 1.0.0.0) and then set the AssemblyFileVersionAttribute to the something based on a CI build number (e.g. 2.0.0.272 for build 272).

For more info on the purpose of these assembly attributes see: http://all-things-pure.blogspot.co.uk/2009/09/assembly-version-file-version-product.html

You can retrieve the value of the Assembly File Version within code.  This can be useful for things like displaying a version number in your UI.  Here’s the code:

var assemblyFileVersion = (AssemblyFileVersionAttribute)Assembly
  .GetExecutingAssembly()
  .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
  .Single();
return assemblyFileVersion.Version;