Server Error in '/' Application.
--------------------------------------------------------------------------------
No parameterless constructor defined for this object.
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.MissingMethodException: No parameterless constructor defined for this object.
Source Error:
Line 16: HttpContext.Current.RewritePath(Request.ApplicationPath, false);
Line 17: IHttpHandler httpHandler = new MvcHttpHandler();
Line 18: httpHandler.ProcessRequest(HttpContext.Current);
Line 19: HttpContext.Current.RewritePath(originalPath, false);
Line 20: }
I was following Steven Sanderson's 'Pro ASP.NET MVC Framework' book. On page 132, in accordance with the author's recommendation, I downloaded the ASP.NET MVC Futures assembly, and added it to my MVC project. [Note: This could be a red herring.]
After this, I could no longer load my project. The above error stopped me cold.
My question is not, "Could you help me fix my code?"
Instead, I'd like to know more generally:
- How should I troubleshoot this issue?
- What should I be looking for?
- What might the root cause be?
It seems like I should understand routing and controllers at a deeper level than I do now.
In my case, my class had the
[Serializable]
attribute.You are required to have a constructor that takes no parameters if your class is
[Serializable]
I got this error. I was using interfaces in my constructor and my dependency resolver wasn't able to resolve, when i registered it then the error went away.
I had a similar problem, and basically the point is that there are some arguments in the action method that were not supplied by the Model Binding process, (and in other words these fields were not submitted by the submitting page).
This problem will come up even if all arguments but one are supplied, and even if the one missing is a nullable type.
The problem might also be a result of a typo, in which the name of the argument and name of the form field will not be identical.
The solution is to 1) verify that the names match up 2) provide a default value for the argument 3) or provide another action method without this argument.
I got the same error when:
Using a custom ModelView, both Actions (GET and POST) were passing the ModelView that contained two objects:
And the POST also accepting the same model view:
Problem was the View received the ModelView (needed both product and list of categories info), but after submitted was returning only the Product object, but as the POST Add expected a ProductModelView it passed a NULL but then the ProductModelView only constructor needed two parameters(Product, RootCategories), then it tried to find another constructor with no parameters for this NULL case then fails with "no parameterles..."
So, fixing the POST Add as follows correct the problem:
Hope this can help somebody (I spent almost half day to find this out!).
I got same exception due to there was no parameterless public contructor
Code was like this:
changed to
problem resolved to me.
I got the same error, the culprit in my case was the constructor which was neither public nor private.
Repro code: Make sure the constructor has public before it.