Copied to clipboard

Flag this post as spam?

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

  • Henrik Bäck 12 posts 72 karma points
    Nov 21, 2017 @ 11:29
    Henrik Bäck

    Help! Unity and Umbraco 7.7.x


    I have trouble with the latest version (7.7.6) of Umbraco and using Unity. If I have Unity enabled I get the following error in the Umbraco backend:

    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at Umbraco.Web.Editors.SectionController.GetSections()
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

    If I disable Unity the backend works as expected. The Unity implementation worked fine in Umbraco v. 7.2.2 and earlier. I have followed the guideline at but I can't get the backend to work.

    Any ideas of how to get things working? My Unity configuration looks like this right now. I've experimented with different techniques for loading all classes in different assemblies but without result.

    public static void RegisterTypes(IUnityContainer container) {
                        new PerHttpRequestLifeTime(),
                        new InjectionFactory(c => UmbracoContext.Current)
                    //container.RegisterTypes(AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()));
                    container.RegisterType<LegacyTreeController>(new InjectionConstructor());
                    container.RegisterType<ISettingsProvider, UmbracoSettingsProvider>(new PerHttpRequestLifeTime());

    I hope there is someone who can give me at least a hint on where to look next. I've tried to follow the code into but without deeper knowledge of Umbraco foundation I get stuck very fast.


  • Dirk De Grave 4539 posts 6012 karma points MVP 3x admin c-trib
    Jan 24, 2018 @ 14:42
    Dirk De Grave

    fwiw, if still struggling to get this working, just found out what needs changing to get it working with unity

            new HierarchicalLifetimeManager(),
            new InjectionFactory(c => UmbracoContext.Current));
        container.RegisterType<HealthCheckController>(new InjectionConstructor());
        container.RegisterType<UserTreeController>(new InjectionConstructor());
        container.RegisterType<Umbraco.Web.Editors.UsersController>(new InjectionConstructor());

    user section has changed quite a lot in v7.7.x, took me too much time to find out it's this specific part of the config that was failing

  • Henrik Bäck 12 posts 72 karma points
    Mar 10, 2018 @ 19:08
    Henrik Bäck

    Thank you! This solved my issues!

  • Ismail Mayat 4511 posts 10061 karma points MVP 2x admin c-trib
    Apr 20, 2018 @ 07:52
    Ismail Mayat


    I am getting similar issue am using ninject. What is the issue that the code you posted is solving? What is stopping the trees from loading? I can then put ninject equivalent.



  • Dirk De Grave 4539 posts 6012 karma points MVP 3x admin c-trib
    Apr 20, 2018 @ 08:09
    Dirk De Grave


    <caution>not an expert on unity</caution>

    I think it's really IoC specific, so not sure if ninject and unity will be equivalent on this... But has to do with the selection of the ctor (if you have both a parameterless ctor and a ctor with one or more parameters) and somehow we need to tell Unity to use a specific ctor (if there's multiple ctor's). Don't know the internals (did more or less a trail and error) but think you need to tell Unity to use the parameterless ctor if possible


Please Sign in or register to post replies

Write your reply to: