Make sure that the controller has a parameterless public constructor.

I am having YSOD with "No parameterless constructor defined" for all controllers, including the Start page  controller,  after upgrading to CMS 11.x .

Using StructureMap.

Any help or tip would be appreciated.

    Server Error in '/' Application. 
 

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) +0System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +139 System.Activator.CreateInstance(Type type, Boolean nonPublic) +105System.Activator.CreateInstance(Type type) +12System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +75 [InvalidOperationException: An error occurred when trying to create a controller of type 'DAP.Web.Controllers.Pages.StartPageController'. Make sure that the controller has a parameterless public constructor.]System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +242System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +258System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +77 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1020System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128  

 
 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0 

Hi,

I have been implemented Episerver Insight like bellow.

It very strange, I don't know why i can't get instance of ICmsTrackingService even i already registered it.

Can anybody show me clue?

System.InvalidOperationException: An error occurred when trying to create a controller of type 'AVG.Web.Controllers.Pages.StandardPageController'. 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, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
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.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
System.InvalidOperationException: An error occurred when trying to create a controller of type 'AVG.Web.Controllers.Pages.StandardPageController'. 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, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
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.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
2020-08-13 14:48:27,359 [107] ERROR AVG.Web.EPiServerApplication: No parameterless constructor defined for this object.

 public interface ICmsTrackingService
    {
        Task TrackPage(PageData pageData, HttpContextBase httpContextBase);
    }

public class CmsTrackingService : ICmsTrackingService
    {
        private readonly ITrackingService _trackingService;
        private readonly IContextModeResolver _contextModeResolver;
        private readonly ISiteDefinitionResolver _siteDefinitionResolver;
        private readonly IContentLoader _contentLoader;
        private readonly ILogger _logger = LogManager.GetLogger(typeof(CmsTrackingService));

        public CmsTrackingService(
            ITrackingService trackingService,
            IContextModeResolver contextModeResolver,
            ISiteDefinitionResolver siteDefinitionResolver,
            IContentLoader contentLoader) {
            _trackingService = trackingService;
            _contextModeResolver = contextModeResolver;
            _siteDefinitionResolver = siteDefinitionResolver;
            _contentLoader = contentLoader;
        }
public virtual async Task TrackPage(PageData pageData, HttpContextBase httpContextBase){
...
}
}

context.Services.AddTransient<ICmsTrackingService, CmsTrackingService>();


  public class StandardPageController : PageControllerBase<StandardPage>
    {

        private readonly ICmsTrackingService _cmsTrackingService;
        public StandardPageController(ICmsTrackingService cmsTrackingService)
        {
            _cmsTrackingService = cmsTrackingService;
        }
}
}