Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • Chris Recknel 2 posts 54 karma points
    Feb 26, 2015 @ 15:21
    Chris Recknel
    0

    Failed to retrieve data for application tree forms: AutoFac IOC, Umbraco 7.2.2 and Forms

    Just installed Umbraco Forms on this site with Autofac running IOC. All other content and setting trees still work, and I can create forms, but I don't see the forms tree under the forms section of the site...

    All my API endpoints are still working

     
       "Message":"An error has occurred.",
       "ExceptionMessage":"Object reference not set to an instance of an object.",
       "ExceptionType":"System.NullReferenceException",
       "StackTrace":"   at Umbraco.Web.Trees.ApplicationTreeExtensions.<TryGetRootNodeFromControllerTree>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Umbraco.Web.Trees.ApplicationTreeController.<GetRootForMultipleAppTree>d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at Umbraco.Web.Trees.ApplicationTreeController.<GetApplicationTrees>d__4.MoveNext()"
    }

    Here is my container code:

    protected override void OnApplicationStarted(object sender, EventArgs e)
            {
                base.OnApplicationStarted(sender, e);
                var builder = new ContainerBuilder();
                // Register your MVC controllers.
                builder.RegisterControllers(typeof(Controllers.HomepageController).Assembly);
                builder.RegisterApiControllers(typeof(Umbraco.Web.UmbracoApplication).Assembly);
                builder.RegisterApiControllers(typeof(Controllers.HomepageController).Assembly);
                
                builder.RegisterModule<AutofacWebTypesModule>();
                builder.RegisterModule<Modules.DalModule>();
                builder.RegisterModule<Modules.BllModule>();
                // OPTIONAL: Register model binders that require DI.
                builder.RegisterModelBinders(System.Reflection.Assembly.GetExecutingAssembly());
                builder.RegisterModelBinderProvider();
                // OPTIONAL: Register web abstractions like HttpContextBase.
                builder.RegisterModule<AutofacWebTypesModule>();
                // OPTIONAL: Enable property injection in view pages.
                builder.RegisterSource(new ViewRegistrationSource());
                // OPTIONAL: Enable property injection into action filters.
                builder.RegisterFilterProvider();
                // Set the dependency resolver to be Autofac.
                var container = builder.Build();
                var resolver = new Autofac.Integration.WebApi.AutofacWebApiDependencyResolver(container);
                GlobalConfiguration.Configuration.DependencyResolver = resolver;
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
                Logic.NuPickerDataSource.DataSourceFactory = type => DependencyResolver.Current.GetService(type);
            }
  • Chris Recknel 2 posts 54 karma points
    Feb 26, 2015 @ 17:28
    Chris Recknel
    102

    A senior Dev here has found the issue, the IOC addition is as follows:

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

    The Umbraco forms assemblies need to be referenced in order to be able to do this we moved the forms assemblies into a lib folder and referenced them there.

    There is service location in ApplicationTreeExtensions line 66 which if you don't step through Umbraco source you won't see.

    I have my tree back and if we run into other issues complaining about controllers, we know what to do :)

  • mark firth 25 posts 45 karma points
    Mar 16, 2015 @ 11:12
    mark firth
    0

    Hi Chris,

     

    I have the same problem with autofac and a custom tree controller the the backoffice.

    What dll contains the "Umbraco forms assemblies"?

    cheers,

    mark

  • mark firth 25 posts 45 karma points
    Mar 17, 2015 @ 09:32
    mark firth
    0

    Just to answer my own problem and it might help others.

    i found this via google:

    http://24days.in/umbraco/2014/iocdi-architecture/

    from which i used this line of code to fix the problem:

    builder.RegisterAssemblyTypes(typeof(MyCustomTreeClass).Assembly).Where(t => !t.IsAbstract && typeof(ApiController).IsAssignableFrom(t)).InstancePerMatchingLifetimeScope(AutofacWebApiDependencyResolver.ApiRequestTag);

    cheers,

    mark

  • Mark Smit 4 posts 84 karma points
    Sep 25, 2015 @ 09:33
    Mark Smit
    0

    In the same category it is now (7.2.8, 7.2.6 was fine) required to do this:

    container.RegisterType<ContentTreeController>().UsingConstructor();
    
Please Sign in or register to post replies

Write your reply to:

Draft