Saturday, August 14, 2010

System.MissingMethodException: No parameterless constructor defined for this object! Does This Error Really Mean What It Says?

System.MissingMethodException: No parameterless constructor defined for this object. What a great error message right? If you are using ASP.NET MVC, You may be fooled into thinking that receiving this message always means that you need to add something to your controllers. It doesn't! That's right - I said it doesn't always mean that. This message, which is about as helpful as a porcupine in your bathtub, can often point to an issue with the routes in your application.

Instead of going through a lengthy explanation about this error, I'm just going to get to the point. This error can be caused by having an incorrect route defined in your global.asax file. To troubleshoot this error, check your global.asax file and make sure that any parameter that is not a required parameter has the UrlParameter.Optional item. For example, id = UrlParameter.Optional. This error can occur if you have a route defined without an action and then you send in an url WITH the action. Making the action equal to UrlParameter.Optional can, in some instances, solve the problem.

Smooches,
Kila

No comments: