2

Upgrading from Sitecore 8.1 to 8.2 update 5, I get the error below when trying to access a page that uses WFFM (which has also been upgraded). All assemblies and config files from the WFFM update package seem to have been installed correctly to the Website folder.

After a bit of googling (found this among others) I suspect that this has something do to with dependency injection gone wrong, but I don't know where to proceed from here to investigate that. We use Castle Windsor as a custom dependency injector and I have not reconfigured this after the upgrade. Do I perhaps need to do that so Sitecores built-in DI can live next to Castle Windsor?

[ArgumentNullException: Value cannot be null.
Parameter name: analyticsTracker]
   Sitecore.Forms.Mvc.Controllers.FormController..ctor(IRepository`1 repository, IAutoMapper`2 mapper, IFormProcessor`1 processor, IAnalyticsTracker analyticsTracker) +471
   Sitecore.Forms.Mvc.Controllers.FormController..ctor() +152

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   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) +159
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +14297981
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +198
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +28
   Sitecore.Mvc.Helpers.TypeHelper.CreateObject(Type type, Object[] parameters) +43
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateControllerInstance(RequestContext requestContext, String controllerName) +350
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +119

[ControllerCreationException: Could not create controller: 'Sitecore.Forms.Mvc.Controllers.FormController, Sitecore.Forms.Mvc'. 
The context item is: '/sitecore/content/something/something/some-page'. 
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) +346
   Sitecore.Mvc.Controllers.ControllerRunner.GetController() +24
   Sitecore.Mvc.Controllers.ControllerRunner.Execute() +50
   Sitecore.Mvc.Presentation.ControllerRenderer.Render(TextWriter writer) +127
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +156
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +62
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +445
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +20
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +221
   Sitecore.Mvc.Pipelines.Response.RenderPlaceholder.PerformRendering.Render(String placeholderName, TextWriter writer, RenderPlaceholderArgs args) +163
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +445
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +20
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +221
   Sitecore.Mvc.Helpers.SitecoreHelper.Placeholder(String placeholderName) +331
   ASP._Views_Layouts_Main_cshtml.Execute() in c:\Code\Something\MyProject\obj\CodeGen\Views\views\layouts\Main.cshtml:75
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +125
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +147
   Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +358

[InvalidOperationException: Error while rendering view: '/Views/Layouts/Main.cshtml' (model: 'Sitecore.Mvc.Presentation.RenderingModel, Sitecore.Mvc').
]
   Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +877
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +156
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +62
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +445
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +20
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +221
   Sitecore.Mvc.Presentation.RenderingView.Render(ViewContext viewContext, TextWriter writer) +318
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +57

EDIT: On some pages that use WFFM, the exception is another:

[Exception: Could not create instance of the Sitecore.Forms.Core.Handlers.FormDataHandler class.]
   Sitecore.WFFM.Abstractions.Dependencies.DependenciesManager.Resolve(String path) +373
   Sitecore.WFFM.Abstractions.Dependencies.DependenciesManager.Resolve() +291
   Sitecore.Form.Core.Ascx.Controls.SimpleForm..ctor() +52
   Sitecore.Form.Web.UI.Controls.SitecoreSimpleForm..ctor(Item item) +45
   Sitecore.Form.Core.Renderings.FormRender.OnInit(EventArgs e) +465
   System.Web.UI.Control.InitRecursive(Control namingContainer) +186
   System.Web.UI.Control.InitRecursive(Control namingContainer) +291
   System.Web.UI.Control.InitRecursive(Control namingContainer) +291
   System.Web.UI.Control.InitRecursive(Control namingContainer) +291
   System.Web.UI.Control.InitRecursive(Control namingContainer) +291
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098
2

It could be that Castle Windsor (to my knowledge) tries to get the constructor with the most parameters. If there are more than one with the same amount of parameters it picks the first... which looks like it's causing those errors.

I had a similar issue on a project a while back. I used Simple Injector and the following example. It fixed my WFFM issue. Although this example using SI, you should be able to do something similar with Castle Windsor.

To fix the issue, I needed to override the Constructor Resolution Behavior. I added the following code to my project:

public class MostResolvableConstructorBehavior : IConstructorResolutionBehavior
{
    private readonly Container container;

    public MostResolvableConstructorBehavior(Container container)
    {
        this.container = container;
    }

    private bool IsCalledDuringRegistrationPhase => !this.container.IsLocked();

    public ConstructorInfo GetConstructor(Type service, Type implementation)
    {
        var constructors = implementation.GetConstructors();

        if (!constructors.Any())
            return null;

        return (
            from ctor in constructors
            let parameters = ctor.GetParameters()
            where this.IsCalledDuringRegistrationPhase
                  || constructors.Length == 1
                  || parameters.All(p => this.CanBeResolved(p, service, implementation))
            orderby parameters.Length descending
            select ctor)
            .First();
    }

    private bool CanBeResolved(ParameterInfo p, Type service, Type implementation)
    {
        return this.container.GetRegistration(p.ParameterType) != null ||
               this.CanBuildType(p, service, implementation);
    }

    private bool CanBuildType(ParameterInfo p, Type service, Type implementation)
    {
        try
        {
            this.container.Options.DependencyInjectionBehavior.BuildExpression(
                new InjectionConsumerInfo(service, implementation, p));
            return true;
        }
        catch (ActivationException)
        {
            return false;
        }
    }
}

Next I added to the InitializeDependencyResolver located in App_Start. That looked like:

var container = new Container();
container.Options.ConstructorResolutionBehavior = new MostResolvableConstructorBehavior(container);

Here are two links that provide really good and in depth information regarding this.

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.