U4-6347 - Autofac: Failing to register Tree Controllers breaks all trees.

Created by Murray Roke 02 Mar 2015, 21:57:23 Updated by Sebastiaan Janssen 18 Jul 2016, 15:58:40

Background: Our project includes Autofac, we register a custom Application which inherits from Umbraco.Web.UmbracoApplication Everything was working until... I installed a nuget package uMigrate, and the developer section now does not show any trees. The exception included at the end of this description is shown in the RHS error pane slide out.

My Resolution: In order to resolve the issue I had to (by guesswork) add the following controller registration.

builder.RegisterApiControllers(typeof (uMigrate.UI.MigrationTreeController).Assembly);

Desired Changes I'm not really sure about the best way to address this, but here's some ideas:

  1. Can the trees be isolated so one failing tree does not affect the others?
  2. Can we have the error convey more information, even which tree is failing would help.
  3. Have some magic/method/advice on how to have Autofac find these controllers in future.

Exception when TreeController is not registered:

Received an error from the server
Failed to retrieve data for application tree developer

Object reference not set to an instance of an object.

EXCEPTION DETAILS:

System.NullReferenceException: Object reference not set to an instance of an object.
STACKTRACE:

at Umbraco.Web.Trees.ApplicationTreeExtensions.<TryGetRootNodeFromControllerTree>d__4.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Umbraco.Web.Trees.ApplicationTreeController.<GetRootForMultipleAppTree>d__12.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Umbraco.Web.Trees.ApplicationTreeController.<GetApplicationTrees>d__4.MoveNext()

Comments

Shannon Deminick 21 Sep 2015, 09:59:16

The best we can do is handle the null reference properly so you get a more detailed exception message. We cannot put anything in the core relating to auto-fac since we don't reference it.


Murray Roke 22 Sep 2015, 21:21:00

That sounds good. Question, how does umbraco register these controllers if autofac is not present, perhaps we can have autofac do the same thing?


Shannon Deminick 06 Oct 2015, 08:31:08

Umbraco doesn't 'register' anything, it doesn't use IoC because we don't want to get in the way of you using IoC. MVC and WebApi don't require IoC, it's up to the developer to choose if they want to use it or not. All containers work slightly differently. Auto-fac (and other containers) have helper methods to scan assemblies for controllers to register. Also since the controller you've mentioned is completely outside of Umbraco core, it will still be up to you to ensure the controllers in that project are registered. You could probably pester that package developer to update their documentation in regards to this.


Priority: Normal

Type: Bug

State: Open

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.2.2, 7.2.8

Due in version:

Sprint:

Story Points:

Cycle: