One of the advantages of open source software is that it assist in troubleshooting and solving errors in your application.
Recently I ran into the following problem with ASP.NET MVC 2.0 RC.
After some searching I found the following post:
ASP.NET MVC 2 problem with UpdateModel
I downloaded the ASP.NET MVC 2 RC source code, extracted the zip file, located the offending method and commented out the problem:
public sealed class FormCollection : NameValueCollection, IValueProvider { public FormCollection() { } public FormCollection(NameValueCollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } Add(collection); } public ValueProviderResult GetValue(string name) {
Commented Code //if (String.IsNullOrEmpty(name)) { // throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name"); //} string[] rawValue = GetValues(name); if (rawValue == null) { return null; } string attemptedValue = this[name]; return new ValueProviderResult(rawValue, attemptedValue, CultureInfo.CurrentCulture); } public IValueProvider ToValueProvider() { return this; } #region IValueProvider Members bool IValueProvider.ContainsPrefix(string prefix) { return ValueProviderUtil.CollectionContainsPrefix(AllKeys, prefix); } ValueProviderResult IValueProvider.GetValue(string key) { return GetValue(key); } #endregion private sealed class FormCollectionBinderAttribute : CustomModelBinderAttribute { // since the FormCollectionModelBinder.BindModel() method is thread-safe, we only need to keep // a single instance of the binder around private static readonly FormCollectionModelBinder _binder = new FormCollectionModelBinder(); public override IModelBinder GetBinder() { return _binder; } // this class is used for generating a FormCollection object private sealed class FormCollectionModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } return new FormCollection(controllerContext.HttpContext.Request.Form); } } } } }
After the solution was built, I copied the output to the Libraries folder of the application:
Removed the existing reference to System.Web.Mvc from the MVC Application and created a reference the the System.Web.Mvc in the Libraries folder.
Then I commented out the System.Web.Mvc GAC-version reference from web.config:
<compilation debug="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <!--<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />--> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> </assemblies> <buildProviders> <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </buildProviders> </compilation>
and updated the /Views/web.config: (Replaced PublicKeyToken=31bf3856ad364e35 with PublicKeyToken=null)
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL"> <controls> <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> <!--<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <controls> <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages>-->
Remember Me
a@href@title, strike
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.