8

We have upgraded our platform to Sitecore 8.2 recently and in the preview we are getting below error. We disabled all glass mapper related config.

No parameterless constructor defined for this object.

Description: An unhandled exception occurred. 

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

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

[InvalidOperationException: An error occurred when trying to create a controller of type 'xxxxxxxxx.xxxxxxxxx.Website.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +76
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +88
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateControllerInstance(RequestContext requestContext, String controllerName) +184
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +68

[ControllerCreationException: Could not create controller: 'Home'. 
The context item is: '/sitecore/content/xxxxxxxxx/xxxxxxxxx-xxxxxxxxx-brand/xxxxxxxxx-xxxxxxxxx/home'. 
The current route url is: '{*pathInfo}'. This is the default Sitecore route which is set up in the 'InitializeRoutes' processor of the 'initialize' pipeline. ]
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +121
   Sitecore.Mvc.Controllers.ControllerRunner.CreateControllerUsingFactory() +53
   Sitecore.Mvc.Controllers.ControllerRunner.CreateController() +5
   Sitecore.Mvc.Controllers.ControllerRunner.GetController() +17
   Sitecore.Mvc.Controllers.ControllerRunner.Execute() +36
   Sitecore.Mvc.Presentation.ControllerRenderer.Render(TextWriter writer) +95
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +15
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +52
   (Object , Object[] ) +59
   Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters) +36
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +365
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +162
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +18
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args) +18
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +138
   Sitecore.Mvc.Helpers.SitecoreHelper.RunRenderRenderingPipeline(Rendering rendering, TextWriter writer) +77
   Sitecore.Mvc.Helpers.SitecoreHelper.<.ctor>b__0(Rendering rendering, StringWriter writer) +5
   Sitecore.Mvc.Helpers.SitecoreHelper.RenderRendering(Rendering rendering) +42
   Sitecore.Mvc.Helpers.SitecoreHelper.Rendering(String pathOrId, Object parameters) +92
   Sitecore.Mvc.Helpers.SitecoreHelper.Rendering(String pathOrId) +12
   ASP._Page_Views_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_Corporate_xxxxxxxxx_xxxxxxxxx_Layouts_LayoutMain_cshtml.Execute() in c:\inetpub\wwwroot\LeicaLocal8.1\Website\Views\xxxxxxxxx\xxxxxxxxx xxxxxxxxx Corporate\xxxxxxxxx xxxxxxxxx\Layouts\LayoutMain.cshtml:7
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +90
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +234
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
   System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +280
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +91
   Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +244

[InvalidOperationException: Error while rendering view: '/Views/xxxxxxxxx/xxxxxxxxx xxxxxxxxx Corporate/xxxxxxxxx xxxxxxxxx/Layouts/LayoutMain.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
]
   Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +513
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +15
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +52
   (Object , Object[] ) +59
   Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters) +36
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +365
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +162
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +18
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args) +18
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +138
   Sitecore.Mvc.Presentation.RenderingView.Render(ViewContext viewContext, TextWriter writer) +216
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +36
  • Just reading the error: do you have a parameterless constructor in your 'Home' controller? – Gatogordo Nov 29 '16 at 7:24
  • Are you using Html.RenderAction or similar in your LayoutMain.cshtml? – Søren Kruse Nov 29 '16 at 7:56
  • 1
    You probably used dependency injection for your controllers before the upgrade. Now the DI setup isn't working anymore, so MVC wants a constructor without arguments. Please see sitecore.stackexchange.com/questions/490 for ways to set up DI with 8.2 – Dmytro Shevchenko Nov 29 '16 at 7:59
  • In order to be able to help you with this particular error, we'll need you to include all DI-related setup (code, configs, etc.) as part of your question. – Dmytro Shevchenko Nov 29 '16 at 8:00
  • sitecore.stackexchange.com/questions/1739/… worth looking at this issue, the answer explains how and where to patch in your DI configuration. – Anicho Nov 29 '16 at 14:52
8

The reason you are getting No parameterless constructor error is because Sitecore cannot create an instance of your controller that takes parameters. Without dependency injection working correctly, Sitecore is looking for a controller that takes not inputs like this:

public ActionResult MyController()
{
   //stuff
}

What you do have is one that takes parameters, like a service or a repository.

private readonly IAccountService _accountService;

public ActionResult MyController(IAccountService accountService)
{
    _accountService = accountService;
}

Your IoC container is responsible for resolving these input parameters for Sitecore, but that seems to not be working now in your solution. Which IoC container you are using is not known yet, but in Sitecore 8.2 an IoC container is available by default. You may consider making the investment to move to that to resolve your issue.

http://kamsar.net/index.php/2016/08/Dependency-Injection-in-Sitecore-8-2/

http://www.sitecorenutsbolts.net/2016/09/17/Habitat-Dependency-Injection-with-Sitecore-8-2/

1

In my case Dependency Injection was not working because the code was in Gloabl.asax.cs and this is not executed anymore in Sitecore 8.2. The solution is to modify Global.asax.cs and inherit from Sitecore.Mvc.Pipelines.Loader.InitializeRoutes instead of Sitecore.Web.Application so you can create the config.

After this you can go ahead and create a config e.g. yourcustomname.config with the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <initialize>
                <processor type="YourGlobalAsaxFullyQualifiedClassName, YourGobalAsaxAssembly" />
            </initialize>
        </pipelines>
    </sitecore>
</configuration>

That's it, publish the code, refresh the app pool and it should work.

-1

Alternate solution is to replace bin folder from your website(explored through IIS) to a new installed version. This should resolve the issue and you should be able to see the basic structure of your site as well see sitecore backend.

After above, clean and build you project in Visual studio and publish the code. Now you should see everything working as expected.

NOTE: I am no expert in sitecore. Above step worked for me, hence posted here so that this can be helpful to others like me and I would suggest to take backup of bin of your website first before deleting anything.

  • Any reason for downgrades..please let me know..will be happy to delete this answer – Bhawna Jain Nov 26 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.