tags:

views:

5608

answers:

6

The callstack shows the following:

[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultModelBinder.CreateModel(ModelBindingContext bindingContext, Type modelType) +277
System.Web.Mvc.<>c__DisplayClass1.<BindModel>b__0() +98
System.Web.Mvc.ModelBindingContext.get_Model() +51
System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +2600
System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067
System.Web.Mvc.DefaultModelBinder.BindProperty(ModelBindingContext parentContext, Type propertyType, Func`1 propertyValueProvider, String propertyName) +208
System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +1787
System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ParameterInfo parameterInfo) +355
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(MethodInfo methodInfo) +439
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +288
System.Web.Mvc.Controller.ExecuteCore() +180
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +96
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +36
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +377
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

I have a tiny form with a bunch of hidden fields and one submit button. When I press it, I never even hit the requested method.

How do I go on and debug this? It would be a great start if I knew WHAT object didn't have a parameterless constructor. Where is this object? How can I solve this? I know the question is rather vague, but currently it's all I've got..

--EDIT--
In my form I added Html.Hidden() inputs. Depending on previous actions, these can have a value of "". The action makes use of ModelBinding. Whenever the value is "" and the datatype is a SelectList, the modelbinder goes berzerk on me.

I feel more and more uncomfortable with how the SelectList is doing it's thing... The idea is good, but there are some issues with it.

+1  A: 

Did you remove Default.aspx? That needs to be in place to render the root properly. This can also happen if you're trying to use Dependency Injection and your container isn't setup properly - meaning there is no ControllerFactory that asks the DI Container for the instance.

Rob Conery
Nope, it's there. I found what the cause is, but not the solution yet.Please refer to my original post.
borisCallens
That was it for me, I copied over code from the WPF app I was testing and I had removed the IControllerFactory controllerFactory = new UnityControllerFactory(_container); ControllerBuilder.Current.SetControllerFactory(controllerFactory);
rball
+5  A: 

Your custom classes in the action args must have a parameterless constructor in order to use the default model binder. Otherwise, either (1) create a custom model binder or (2) pass primitive types instead of custom classes to the Action.

Craig Stuntz
Thanks for the answer. This was actually the first thing I checked because it was the most obvious thing that could go wrong. They do have a parles ctor. I use the same objects throughout the rest my site sucessfully.
borisCallens
+1  A: 

I Am facing the exact same scenario and unable to trace it into any where

Gripsoft
+2  A: 

I solved the issue which is caused of SelectList object because it does not provide the default constructor so we cant have in out ViewModel.

Gripsoft
Ic, thanks for the response :)
borisCallens
A: 

I came across this and found my problem was that I'd created a class that inherited from TemplateField and was adding objects of this type to a GridView column collection. ViewState was enabled on the grid and the form was trying to recreate the columns on postback. The problem was I hadn't created a parameterless constructor on the new class. Bit of a tricky one to debug as there wasn't anything identifying the problem type in the exception. Have a check for anything being reconstructed from ViewState.

sl
+3  A: 
Roger Helliwell
So then the selectlist values need to be retrieved from the forms collection.
Aros