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); }
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 :)
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
Here is my container code:
A senior Dev here has found the issue, the IOC addition is as follows:
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 :)
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
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
In the same category it is now (7.2.8, 7.2.6 was fine) required to do this:
is working on a reply...