Backoffice GetApplicationTree API Call throwing error after setting DependencyResolver to AutofacDependencyResolver
I'm using Umbraco 7.4.2 and went through this article to setup Autofac into my solution but after setting it all up, I noticed the backoffice started throwing errors.
My code for registering my components:
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var builder = new ContainerBuilder();
//register all controllers found in this assembly
builder.RegisterControllers(Assembly.GetExecutingAssembly());
//register umbraco webapi controllers used by the admin site
builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
And the error I'm getting from the backoffice on this call - /umbraco/backoffice/UmbracoTrees/ApplicationTree/GetApplicationTrees?application=users&tree=&isDialog=false:
"Message":"An error has occurred.",
"ExceptionMessage":"Object reference not set to an instance of an object.",
"ExceptionType":"System.NullReferenceException",
"StackTrace":" at Umbraco.Web.WebApi.Filters.DisableBrowserCacheAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, 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.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>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.<ExecuteActionFilterAsyncCore>d__0.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__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>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.<ExecuteActionFilterAsyncCore>d__0.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__2.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__2.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__1.MoveNext()""
Did some debugging and found commenting this line solves the backoffice issue:
Backoffice GetApplicationTree API Call throwing error after setting DependencyResolver to AutofacDependencyResolver
I'm using Umbraco 7.4.2 and went through this article to setup Autofac into my solution but after setting it all up, I noticed the backoffice started throwing errors.
My code for registering my components:
And the error I'm getting from the backoffice on this call - /umbraco/backoffice/UmbracoTrees/ApplicationTree/GetApplicationTrees?application=users&tree=&isDialog=false:
Did some debugging and found commenting this line solves the backoffice issue:
But then I can't use DI for my controllers.
Thoughts anyone? Thanks in advance.
I'm having the same issue. Up ^
If it's occurs for custom package like Forms or Merchello need register it's
Merchello builder.RegisterApiControllers(typeof(Merchello.Web.MerchelloHelper).Assembly);
Forms builder.RegisterApiControllers(typeof(Umbraco.Forms.Web.Trees.DataSourceTreeController).Assembly);
Like Yakov Lebski wrote, you need to register the controllers and api controllers of all the custom packages you have installed.
This could be Merchello, UmbracoForms or other back office extensions.
Hope you get it working soon
/Martin
is working on a reply...