I'm using ASP.NET MVC 4.0.40804. This is my Code:
public class FilesController : MyController
{
public ActionResult List(int product, Dictionary<int, string> files)
{
return View();
}
}
And this is the request:
http://localhost:7135/Files/List?product=2
I would expect that the "files" dictionary is null, however it crashes with "Specified cast is not valid". (see below). I believe the problem is related to this ASP.NET MVC bug report.
Is this actually a bug in ASP.NET MVC, or am I doing something wrong?
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid. [InvalidCastException: Specified cast is not valid.]
System.Web.Mvc.CollectionHelpers.ReplaceDictionaryImpl(IDictionary2 dictionary, IEnumerable1 newContents) +131[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +108 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
System.Web.Mvc.CollectionHelpers.ReplaceDictionary(Type keyType, Type valueType, Object dictionary, Object newContents) +178
System.Web.Mvc.DefaultModelBinder.UpdateDictionary(ControllerContext controllerContext, ModelBindingContext bindingContext, Type keyType, Type valueType) +1211 [..