Windows Azure, MVC3, No parameterless constructor

2019-08-06 03:49发布

问题:

I am trying to upload an local perfectly running ASP.NET MVC3 Application to Windows Azure.

When I uploaded the Application to azure, it is shown as "Ready". But if I call it, there appears the following Error:

No parameterless constructor defined for this object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[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 'DummyAnwendung.Controllers.AccountController'. 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) +280
   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() +389
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

Has somebody an idea, what the error could cause? I am using for DI the Unity Application Block..

Best Regards Pat

回答1:

The error message states the following:

'DummyAnwendung.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor

If you do not define a constructor for a class, a parameterless constructor will be created. However, if you define a constructor with parameters, no parameterless constructor will be created.

Define a parameterlass constructor for this class.