Our current project is written in ASP.NET MVC 1 using mvc-turbines (and unity) for IOC/DI.
我们当前的项目是用ASP写的。NET MVC 1使用MVC涡轮机(和unity)进行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.
当我尝试从2008年开始启动应用程序时,一切都很正常,但从2010年开始,我一直得到“无参数构造函数”——错误。
Why? Both are targeting the same .Net framework. The VS 2010 solution keeps using the default controller factory. Any suggestions to debug this?
为什么?两者都以相同的。net框架为目标。VS 2010解决方案一直使用默认的控制器工厂。有什么建议来调试这个吗?
[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& controller, 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
1 个解决方案
#1
1
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.
我假设在您的HttpApplication (Global.asax.cs)的Application_Start()方法中,您将控制器工厂设置为您的自定义控制器工厂。
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).
我相信正在发生的事情是在执行这一行代码之前,在Application_Start()中有一个异常被抛出。如果发生这种情况,对web应用程序的任何后续调用都将绕过此异常,这可能导致应用程序出现错误行为(例如不使用自定义控制器工厂)。
I would debug Application_Start() and make sure it is executing correctly. If you're using ELMAH, then the exception should get logged.
我将调试Application_Start()并确保它正在正确执行。如果您正在使用ELMAH,那么应该记录异常。
#1
1
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.
我假设在您的HttpApplication (Global.asax.cs)的Application_Start()方法中,您将控制器工厂设置为您的自定义控制器工厂。
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).
我相信正在发生的事情是在执行这一行代码之前,在Application_Start()中有一个异常被抛出。如果发生这种情况,对web应用程序的任何后续调用都将绕过此异常,这可能导致应用程序出现错误行为(例如不使用自定义控制器工厂)。
I would debug Application_Start() and make sure it is executing correctly. If you're using ELMAH, then the exception should get logged.
我将调试Application_Start()并确保它正在正确执行。如果您正在使用ELMAH,那么应该记录异常。