我们的生产环境中的一台 Web 服务器上出现奇怪的错误:MissingMethod 异常,尽管我不认为缺少方法
我们正在运行一个分布在负载平衡的 3 个 Web 服务器上的 Web 应用程序。完全相同的代码库和配置部署在 3 台服务器上,大约 1 小时前,我在其中一台服务器上收到以下错误,但在另外两台服务器上则没有。
System.InvalidOperationException: An error occurred when trying to create a controller of type 'XXX.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我们使用 ASP.NET MVC(带有输出缓存)、NHibernate(带有 NHibernate 缓存)和 ASP.NET MVC 来运行它。结构图。缓存不共享,因此每个 Web 服务器都管理自己的缓存,尽管 3 个服务器之间的缓存依赖关系是相同的。
我真的不知道从哪里开始描述可能出错的地方或情况,因为这对我来说太奇怪了。
大约两周前我见过一次这种情况,但大约一个小时后它就自行消失了,此后我就再也没有见过它。以前有其他人见过这样的错误吗?
We're running a web application distributed across load balanced 3 web servers. The exact same code base & configuration is deployed across the 3 servers, and since about 1 hour ago I'm getting the following error on one of them, but not the other two.
System.InvalidOperationException: An error occurred when trying to create a controller of type 'XXX.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
We are running this with ASP.NET MVC (with Output Caching), NHibernate (with NHibernate caching) & StructureMap. The cache is not shared, so each web server manages its own cache, though the cache dependencies are the same across the 3 servers.
I don't really know where to start describing what/where it could be going wrong or the circumstances, because it's so strange to me.
I've seen this once before about 2 weeks ago, but it went away on its own after about an hour and I haven't seen it since. Has anyone else seen an error like this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,看来你的 HomeController 缺少一个无参数构造函数。你确定它有一个吗?
默认控制器工厂需要一个来初始化您的构造函数。
除非你使用自己的ControllerFactory,在这种情况下你需要在Application_Start期间注册它:
Well, it seems your HomeController is missing a parameterless constructor. Are you sure it has one?
The default controller factory needs one to intialize your constructor.
Unless you are using your own ControllerFactory, in which case you need to register it during Application_Start:
假设您正在使用结构图解析控制器,则可能是您的组件在错误的地点/时间注册了。
您是否在 Application_Start 中注册组件?
Assuming you're resolving controllers with structuremap, it may be your components are registered at the wrong place/time.
Are you registering components in Application_Start ?