ASP.NET MVC: An Error has occured when trying to create a controller
- by Grayson Mitchell
I have got the following error a few times in my MVC applications, and have only managed to get past it by recreating my entire solution from scratch. The error message says make sure there is a paramaterless public constructor, but of course there is one. What else could this error refer to? (It looks like it can't find the controller at all)
Code where error occurs
public void Page_Load(object sender, System.EventArgs e)
{
// Change the current path so that the Routing handler can correctly interpret
// the request, then restore the original path so that the OutputCache module
// can correctly process the response (if caching is enabled).
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
**httpHandler.ProcessRequest(HttpContext.Current);**
HttpContext.Current.RewritePath(originalPath, false);
}
Error Message
An error occurred when trying to create a controller of type 'Moe.Tactical.Ttas.Web.Controllers.TtasController'. Make sure that the controller has a parameterless public constructor.