ASP.NET MVC MissingMethodException April 9, 2012
Posted by kevinbe71 in MVC.add a comment
I was troubleshooting an issue recently that produced a “No parameterless constructor defined for this object”. I have a BaseController class that overrides the Execute method and was seeing the exception thrown when it called base.Execute. The error message was accurate but it wasn’t obvious where the error was occurring. It turned out that an Ajax POST method call that was being handled in one of the controllers was to blame. It had a parameter that was a complex class with a nested class that didn’t have a parameterless constructor. Moral of the story… Check all of your types carefully to make sure that all contained types also have parameterless constructors because ASP.NET MVC requires this when marshaling the types.
ASP.NET detected invalid characters in the URL (HTTP Error 400.0 – Bad Request) April 8, 2009
Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.2 comments
I ran into this error when writing a web app using ASP.NET MVC and using a comma in one of the input params used in the URL. IIS 7 reported the error in the following way:
In “Error Summary” it had “HTTP Error 400.0 – Bad Request” and “ASP.NET detected invalid characters in the URL.”
In “Detailed Error Information” the Request URL was something like this and hovering over the link showed the same URL:
http://localhost/BaseUrl/Some_Path%2c_And_More/View
In the browser’s address box the URL was displayed as:
http://localhost/BaseUrl/Some_Path%252c_And_More/View
The comma was being double-encoded (%2c –> %252c) ! I didn’t spot the difference at first until I used the W3 Schools reference on URL encoding (http://www.w3schools.com/TAGS/ref_urlencode.asp) and noticed the encoding of %.
So, in the end the solution was to remove the bit of code that was doing the extra URL encoding. Pretty simple really…
Using ASP.NET MVC From Visual Web Developer Express 2008 April 19, 2008
Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.Tags: ASP.NET MVC
2 comments
Recently I’ve been curious about Microsoft’s ASP.NET MVC framework that is currently at “Preview 2″ stage (although there may be more recent CTPs floating around). I’ve read a bit about it and felt it was time to actually dig in and start writing a web site that uses the technology. I don’t own a copy of VS 2008 so I figured I’d download VWD Express 2008 and play around with it. Well, the problem is that ASP.NET MVC doesn’t specifically support it. Fortunately, I found a blog posting by Jason Whitehorn that got me started. However, I couldn’t get it working immediately. I ran into two issues that I’ll explain below. I figure that this may be helpful to others.
Jason Whitehorn’s blog posting here:
http://jason.whitehorn.ws/CommentView.aspx?guid=…
Jason provides all the pieces of the puzzle but his page is missing a few minor points that a newbie may run into:
- Downloading the zipped template to the Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer folder doesn’t appear to work at first if you download the C# template. The reason for this is that VWD defaults to VB as a language. All you need to do is select C# from the drop-down list and the template will appear. Another mistake a newbie might make is to unzip this file. Don’t- it won’t be found if it isn’t zipped.
- You should change the VirtualPath property of your web site from “/<your_web_site_name>” to just “/”. Otherwise you’ll need to build routes that include your web site name as the first part of the URL- not preferable. If you don’t do this you may end up with the error shown below.
The RouteData must contain an item named ‘controller’ with a non-empty string value.
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.InvalidOperationException: The RouteData must contain an item named ‘controller’ with a non-empty string value.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The RouteData must contain an item named 'controller' with a non-empty string value.]
System.Web.Mvc.RouteData.GetRequiredString(String keyName) +201
System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +139
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.
ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.
HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Anyway, I hope this will be helpful to someone else who encounters this error. Jason’s blog post isn’t accepting comments so I couldn’t post this “answer” there.