开发者

ASP.NET MVC 1: "No parameterless constructor"-error after moving to VS2010 (using MVCTurbines)

Our current project is written in ASP.NET MVC 1 using mvc-turbines (and unity) for IOC/DI.

When I try to start the application from 2008 everything works fine, but from 2010 I keep getting the "No parameterless constructor"-error.

Why? Both are targeting the same .Net framework. The VS 2010 solution keeps using the default controller factory. Any suggestions to debug this?

[MissingMethodException: No parameterless constructor defined for this object.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80

[InvalidOperationException: An error occurred when trying to create a controller of type 'CommonProject.Web.Shared.Controllers.MyController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +190
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +68
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controll开发者_Python百科er, IControllerFactory& factory) +118
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +46
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.Mvc.MvcHttpHandler.VerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext) +61
   System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) +111
   System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) +40
   System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +7
   CommonProject.Web._Default.Page_Load(Object sender, EventArgs e) in 


I am assuming that in the Application_Start() method of your HttpApplication (Global.asax.cs) you are setting the controller factory to be your custom controller factory.

I believe what is happening is that prior to this line of code executing, an exception is being thrown somewhere in Application_Start(). If this happens, any subsequent call to the web application will bypass this exception, which can result in your application misbehaving (such as not using your custom controller factory).

I would debug Application_Start() and make sure it is executing correctly. If you're using ELMAH, then the exception should get logged.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜