Take the 2-minute tour ×

Disclaimer: Yes, I've googled and read through the top six or so hits, searched on SO and found lots of other posts, but neither of them has helped me resolve this... This one, and particularly this answer, seems to come pretty close, but I still can't figure it out. Thus, please bear with me even though I seem to ask a question that has been asked many times before.


When I submit a form, I get a System.MissingMethodException saying "No parameterless constructor defined for this object." There seems to be a number of different, fairly common, causes for this - the two most prominent being that the Controller lacks a default constructor and doesn't have it's dependencies satisified when the DI framework tries to resolve it, respectively that the input model on the action method doesn't have a default constructor. From my stack trace, I've deduced that the latter seems to be my problem - however, I've come nowhere trying to troubleshoot this.

Background info

My stack trace:

[MissingMethodException: No parameterless constructor defined for this object.]

System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +117
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +247
System.Activator.CreateInstance(Type type, Boolean nonPublic) +106
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +243
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +151
etc... it goes on for a while...

However, my model does have a parameterless constructor (see code below)!

My POST action method signature:

public ActionResult AddObject(InspectionObjectEditModel input, IUser user)
// IUser is passed with a custom model binder, that is verified to work

My GET action method, that shows the form:

public ActionResult CreateObject()
    var model = GetEditModelForID(0); // Calls new InspectionObjectEditModel()
    model.PostAction = "AddObject";
    return View(model);

The InspectionObjectEditModel:

public class InspectionObjectEditModel : ViewModel<InspectionObject, int>, IInspectionObjectData
    // ReSharper warns on the constructor, because it's redundant
    public InspectionObjectEditModel() { }

    #region Properties for editing
    public virtual string Littera { get; set; }
    public virtual InspectionObjectType Type { get; set; }
    [Required, NotNull]
    public virtual string Name { get; set; }
    public virtual string Owner { get; set; }
    public virtual string Address { get; set; }
    public virtual string Caretaker { get; set; }
    public virtual string Remarks { get; set; }
    public virtual float PlacementX { get; set; }
    public virtual float PlacementY { get; set; }
    public virtual float PlacementZ { get; set; }

    #region Data for form elements
    public virtual List<InspectionObjectType> Types { get; set; }
    public virtual bool Geocode { get; set; }

    //public Expression<Action<InspectionController>> PostAction { get; set; }
    public virtual string PostAction { get; set; }

    #region Properties that won't be edited
    public virtual Project Project { get; set; }
    public virtual DateTime Created { get; set; }
    public virtual User CreatedByUser { get; set; }
    public virtual DateTime? LastUpdated { get; set; }
    public virtual User LastUpdatedByUser { get; set; }
    public IList<InspectionActivity> Activities { get; set; }
share|improve this question

3 Answers 3

up vote 4 down vote accepted

If InspectionObjectType doesn't have a parameterless constructor it may cause that exception. Not only does your model class need a parameterless constructor, I believe the types of its public properties do as well.


I think you are increasing your chances of problems by using such a complex class for your model. I have always preferred to keep my view models as simple as possible - really simple. You can then use an auto mapper to transfer to a more full featured object, or use aggregation, or if there are only a few properties, just do it property by property in your controller action method.

share|improve this answer
InspectionObjectType does (in the same, redundant way InspectionObject does) have a default constructor. I had this working with interface types before, but just in case - does that mean I can't have IList<T>, IEnumerable<T> etc as property types? –  Tomas Lycken Jul 19 '11 at 13:53
OK, I solved it by introducing a new InputModel class. I was trying to use the same type for rendering the edit view as for retrieving the changes, which didn't work since some of the referenced types didn't have constructors. I don't want to change them, since this is a pretty big application and I don't want to risk breaking anything, but introducing another viewmodel is OK. The new viewmodel class only has properties for the stuff that will always be there. –  Tomas Lycken Jul 19 '11 at 15:53

The problem is that some of the types used in this monster domain model don't have default constructors: InspectionActivity, User, Project, InspectionObjectType or some of the properties they are referencing, or some of the objects used in the base class ViewModel<InspectionObject, int>. Using view models really would make things simpler.

share|improve this answer

Did you forgot to fill a Parameter? It throw this Exception when you dont have filled all parameters of the Method

share|improve this answer

Your Answer


