Copied to clipboard

Flag this post as spam?

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

  • Ozkan Sayin 6 posts 136 karma points
    Sep 28, 2017 @ 19:08
    Ozkan Sayin

    Umbraco Cloud (7.7.1) & Dependency Injection

    Hey there,

    I am trying to use Dependency Injection with an Umbraco Cloud instance on my local computer. I'm using Autofac (4.6.1), Autofac.Mvc5 (4.0.2) & Autofac.WebApi2 (4.1.0) Although it works fine for my controllers & classes, I am getting errors on the following requests when on the backoffice: enter image description here I don't get the sections on the left (Content, Media, Settings, etc), but I get the content tree. enter image description here Here's the code I use for DI configuration:

            var executingAssembly = Assembly.GetExecutingAssembly();
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    Everything works fine when I disable DI, by commenting out this line

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    Any ideas? Sorry for the long post, and thanks for reading.

    Finally, here's the error in the log file:

    2017-09-28 21:58:56,964 [P11936/D18/T37] ERROR Umbraco.Web.Editors.SectionController - Unhandled controller exception occurred System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at Umbraco.Web.Trees.ApplicationTreeExtensions.

  • Dave Woestenborghs 3227 posts 10923 karma points MVP 5x admin c-trib
    Sep 28, 2017 @ 19:33
    Dave Woestenborghs

    Hi Ozkan,

    I think this is because Cloud has Diplo Trace log viewer and Umbraco forms installed.

    We have this in our Autofac config on Cloud

     // Register extensions

    And that seems to work fine (on 7.6.x)


  • Dennis Adolfi 1071 posts 6352 karma points MVP 2x c-trib
    Dec 10, 2018 @ 11:09
    Dennis Adolfi

    Thank you for this Dave!!!!!!!!!!

  • Ozkan Sayin 6 posts 136 karma points
    Sep 28, 2017 @ 19:41
    Ozkan Sayin

    Worked like a charm by registering Diplo & Forms api controllers.

    Huge thanks, Dave, lightning-fast & spot-on response appreciated!

  • Dave Woestenborghs 3227 posts 10923 karma points MVP 5x admin c-trib
    Sep 28, 2017 @ 19:54
    Dave Woestenborghs

    No problem,

    Basicly every package that creates a tree that inherits from TreeController needs to be registered. Haven't found a generic way yet.


  • Nicholas Westby 1935 posts 6501 karma points c-trib
    Feb 08, 2019 @ 23:00
    Nicholas Westby

    I found a way to do this generically:

    // Get all assemblies that have a tree controller.
    var treeType = typeof(Umbraco.Web.Trees.TreeController);
    var assemblies = AppDomain.CurrentDomain.GetAssemblies()
        .SelectMany(x =>
                return x.GetTypes() ?? new Type[0];
                return new Type[0];
        .Where(x => treeType.IsAssignableFrom(x))
        .Select(x => x.Assembly)
        .DistinctBy(x => x.FullName)
    // Register all controllers in assemblies containing tree controllers.
    foreach (var assembly in assemblies)

    Then you don't even need to worry about doing this:


    From this documentation:

    Because the above code finds that assembly too.

    Note that I don't really understand why this is necessary, but it seems to work, so thought I'd share the code that got it to work. Use this code with caution.

Please Sign in or register to post replies

Write your reply to: