1

我使用 Visual Studio 2012 RC 编写了一个 MVC 4 应用程序。它使用 Ninject 作为依赖注入器,并且在我的本地机器上使用 Azure Emulator 可以正常工作。该应用程序面向 .NET 4.0。但是,当我将它作为 Web 角色部署到 Azure 时,我得到了这个异常:

[MissingMethodException: No parameterless constructor defined for this object.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +117
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +247
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +106
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +84

[InvalidOperationException: An error occurred when trying to create a controller of type 'Poller.WebUI.Controllers.QuestionsController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +85
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +270
   System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +66
   System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +19
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +161
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

我不想将无参数构造函数添加到 QuestionsController,因为我需要那里的数据库存储库,它作为构造函数参数传递。此参数应由 Ninject 正确填写。

有人知道这里可能有什么问题吗?

4

1 回答 1

0

我也遇到了这个问题。我想说,在我们的案例中,我们必须确保我们的 MVC 应用程序使用的是 Windows 2008 R2,而不是 Windows 2008 SP1。您可以更新您的配置文件OS="2"或只登录到管理面板,选择您的网络角色,然后单击升级操作系统。不能确定这是否是您的问题,但它适用于 MVC 3 站点上的我们。

于 2012-07-13T12:52:28.040 回答