Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jacky 1 post 71 karma points
    Mar 25, 2016 @ 11:19
    Jacky
    0

    Backoffice GetApplicationTree API Call throwing error after setting DependencyResolver to AutofacDependencyResolver

    I'm using Umbraco 7.4.2 and went through this article to setup Autofac into my solution but after setting it all up, I noticed the backoffice started throwing errors.

    My code for registering my components:

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        var builder = new ContainerBuilder();
    
        //register all controllers found in this assembly
        builder.RegisterControllers(Assembly.GetExecutingAssembly());
    
        //register umbraco webapi controllers used by the admin site
        builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
    
        var container = builder.Build();
        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
    }
    

    And the error I'm getting from the backoffice on this call - /umbraco/backoffice/UmbracoTrees/ApplicationTree/GetApplicationTrees?application=users&tree=&isDialog=false:

    "Message":"An error has occurred.",
    "ExceptionMessage":"Object reference not set to an instance of an object.",
    "ExceptionType":"System.NullReferenceException",
    "StackTrace":"   at Umbraco.Web.WebApi.Filters.DisableBrowserCacheAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
       at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
       --- End of stack trace from previous location where exception was thrown ---
          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
             --- End of stack trace from previous location where exception was thrown ---
                at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
                --- End of stack trace from previous location where exception was thrown ---
                   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                         at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
                         --- End of stack trace from previous location where exception was thrown ---
                            at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
                         --- End of stack trace from previous location where exception was thrown ---
                            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                               at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                                  at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
                                  --- End of stack trace from previous location where exception was thrown ---
                                     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                                           at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
                                           --- End of stack trace from previous location where exception was thrown ---
                                              at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                                                 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                                                    at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
                                                    --- End of stack trace from previous location where exception was thrown ---
                                                       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                                                          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                                                          at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()""
    

    Did some debugging and found commenting this line solves the backoffice issue:

    DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    

    But then I can't use DI for my controllers.

    Thoughts anyone? Thanks in advance.

  • Cimplex 113 posts 576 karma points
    Mar 30, 2016 @ 16:28
    Cimplex
    0

    I'm having the same issue. Up ^

  • Yakov Lebski 591 posts 2346 karma points
    Mar 31, 2016 @ 08:29
    Yakov Lebski
    1

    If it's occurs for custom package like Forms or Merchello need register it's

    Merchello builder.RegisterApiControllers(typeof(Merchello.Web.MerchelloHelper).Assembly);

    Forms builder.RegisterApiControllers(typeof(Umbraco.Forms.Web.Trees.DataSourceTreeController).Assembly);

  • Martin Almström 33 posts 159 karma points
    Mar 31, 2016 @ 08:37
    Martin Almström
    0

    Like Yakov Lebski wrote, you need to register the controllers and api controllers of all the custom packages you have installed.

    This could be Merchello, UmbracoForms or other back office extensions.

    Hope you get it working soon

    /Martin

Please Sign in or register to post replies

Write your reply to:

Draft