Copied to clipboard

Flag this post as spam?

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


  • nickornotto 397 posts 900 karma points
    Jun 07, 2020 @ 09:26
    nickornotto
    0

    Umbraco trees stops working when using Autofac global.asax setup

    I have installed Autofac (5.1.2) to use dependency injection on one of dependent project of the solution (not in the starting project).

    Since then the backoffice of our Umbraco 7.15.3 stopped working properly and the main menu not showing up (content tree is showing though).

    The app reports an error on getting sections:

    An error occured
    One or more errors occurred.
    
    Exception Details
    System.AggregateException: One or more errors occurred.
    Stacktrace
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at Umbraco.Web.Editors.SectionController.GetSections()
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, 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.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.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__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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__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.<CallOnActionExecutedAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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__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.<CallOnActionExecutedAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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__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.<CallOnActionExecutedAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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__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.<CallOnActionExecutedAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.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__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.Controllers.ActionFilterResult.<ExecuteAsync>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.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.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__3.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__3.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.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.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__15.MoveNext()
    Inner Exception
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Umbraco.Web.Trees.ApplicationTreeExtensions.<TryGetRootNodeFromControllerTree>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 Umbraco.Web.Trees.ApplicationTreeController.<GetRootForMultipleAppTree>d__1.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 Umbraco.Web.Trees.ApplicationTreeController.<GetApplicationTrees>d__0.MoveNext()
    

    This is my global.asax setup:

    namespace MyDomain.Search
    {
        public class MvcApplication : ApplicationEventHandler
        {
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
                RouteConfig.RegisterRoutes(RouteTable.Routes);
            }
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
                RegisterIoCContainer();
            }
    
            private void RegisterIoCContainer()
            {
                var builder = new ContainerBuilder();
    
                builder.RegisterControllers(Assembly.GetExecutingAssembly());
                builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());
                builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
                builder.RegisterModelBinderProvider();
    builder.RegisterApiControllers(typeof(Controllers.SearchResultsApiController).Assembly);
                builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
    
                builder.RegisterModule<WebApiConfig>();
    
                var container = builder.Build();
    
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
                GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            }
        }
    }
    

    This is my WebApiConfig.cs:

    namespace MyDomain.Search
    {
        public class WebApiConfig : Module
        {
            protected override void Load(ContainerBuilder builder)
            {
                builder.RegisterType<DictionaryHelper>().As<IDictionaryHelper>();
                builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()).AsClosedTypesOf(typeof(IFileDataService<>));
                builder.RegisterGeneric(typeof(FileDataService<>)).As(typeof(IFileDataService<>));
                builder.RegisterType<SearchService>().As<ISearchService>();
                builder.AddMediatR(this.GetType().Assembly);
    
                //builder.Register(c => UmbracoContext.Current).AsSelf();
                builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
                builder.Register(c => UmbracoContext.Current).InstancePerRequest();
                builder.Register(x => new UmbracoHelper(UmbracoContext.Current)).InstancePerRequest();
            }
        }
    }
    

    The setup is in the project where I use autofac and dependency injection - and just to repeat - it's not the startup project. However I tried to add the same configuration to the startup project's global.asax but it didn't fix anything.

    I have looked through solutions of similar issues but none of them works for me really.

    Any idea what I can change in my configuration to fix it?

  • Yakov Lebski 553 posts 2117 karma points
    Jun 08, 2020 @ 04:39
    Yakov Lebski
    0

    you should register

    builder.RegisterControllers(typeof(UmbracoApplication).Assembly);
    builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
    

    you can see complete reference here https://our.umbraco.com/Documentation/Reference/Using-Ioc/index-v7

  • nickornotto 397 posts 900 karma points
    Jun 08, 2020 @ 10:01
    nickornotto
    0

    Thanks for reply.

    I found it out after I wrote this question and I currently have:

        private void RegisterIoCContainer()
        {
            var builder = new ContainerBuilder();
    
            builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
    
            builder.RegisterControllers(typeof(UmbracoApplication).Assembly);
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
    
            builder.RegisterModule<WebApiConfig>();
    
            var container = builder.Build();
    
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
    

    but it's still throwing GetSections() error.

  • Yakov Lebski 553 posts 2117 karma points
    Jun 08, 2020 @ 12:42
    Yakov Lebski
    0

    May be you have additional plugins what add tree section like forms? in case what yes you need register it too

  • nickornotto 397 posts 900 karma points
    Jun 08, 2020 @ 14:50
    nickornotto
    0

    We have Umbraco Forms installed (via Developer > Packages not nuget) and I saw this post: https://our.umbraco.com/forum/using-umbraco-and-getting-started/84819-autofac-not-working

    Though I can't see any Umbraco forms dll or assembly in my references so it's not possible to do this:

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

    because there is no Umbraco.Forms available even in the start up project. Also my global.asax is in the project which has no umbraco forms installed at all so the dll won't be there even more.

    Btw I added the same glabal.asax configuration to the starting project and tried this in both projects (as advised here https://our.umbraco.com/forum/using-umbraco-and-getting-started/84819-autofac-not-working):

    builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
    

    but it didn't help anything.

    Of additional plugins we only have Umbraco forms, uSync & NestedContent and only forms add a section.

  • nickornotto 397 posts 900 karma points
    Jun 08, 2020 @ 15:27
    nickornotto
    0

    Ah and we have also our custom section but it is in another separate project that has no global.asax and it doesn't use DI as yet.

    To clarify it all looks like this:

    -- Search

    ---- global.asax // (that is causing issues)

    -- Backoffice // (project that holds out custom section setup, it has no global.asax)

    -- Web // (startup project where Umbraco Forms is installed)

    ---- global.asax (currently has the same configuration as Search's global.asax above)

  • nickornotto 397 posts 900 karma points
    Jun 10, 2020 @ 21:10
    nickornotto
    100

    We have removed Umbraco Forms as we weren't using them anyway and it all started working.

    I wonder if there is any documentation on how to register UmbracoForms in global.asax in such case?

    I can't imagine such a popular plugin would not be documented in this case. I haven't found anything myself though.

  • Yakov Lebski 553 posts 2117 karma points
    Jun 11, 2020 @ 03:37
    Yakov Lebski
    0

    You need register all plugins or packages when you using DI I Umbraco 8 it much better

    I think you need register controllers and apicontrollers as well

        builder.RegisterControllers(typeof(Umbraco.Forms.Web.Trees.DataSourceTreeController).Assembly);
    builder.RegisterApiControllers(typeof(Umbraco.Forms.Web.Trees.DataSourceTreeController).Assembly);
    
  • nickornotto 397 posts 900 karma points
    Jun 12, 2020 @ 07:37
    nickornotto
    0

    We are using Umbraco 7 for now.

    I have mentioned in one of my previous posts that those types did not exist in our solution despite we had Umbraco Forms installed so we could not register them in global.asax.

Please Sign in or register to post replies

Write your reply to:

Draft