No parameterless constructor defined for this object in Asp.Net MVC

Dung Do Tien Sep 25 2021 170

Hello Guys, I have a project with Asp.Net Framwork MVC version 4.6. 

My project work very well for me but when I deployed it into IIS server by using docker cicd to auto deploy code to IIS server. many time before deploy always worked for me but today I deploy and get an exception: No parameterless constructor defined for this object.

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, StackCrawlMark& stackMark) +114
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 System.Activator.CreateInstance(Type type) +6 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55

[InvalidOperationException: An error occurred when trying to create a controller of type 'Config.Controllers.SiteController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +179
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +197 System.Web.Mvc.

I research and lost many time but still not solve it.

Thanks for any suggestion.

Have 1 answer(s) found.
  • M

    MSIIIXI Sep 25 2021

    Hi Guy, I got same error  and reason is my docker keep some files and not allow. I try deploy in local and copy paste to server IIS and everything worked for me.

    So please check your CI/CD setting.

    I hope it solve for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close