Copied to clipboard

Flag this post as spam?

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


  • mmaty 99 posts 228 karma points
    Sep 21, 2020 @ 16:15
    mmaty
    0

    Umbraco Boot Failed - UmbracoContext is null

    Hi all,

    I did an upgrade to an Umbraco installation to v. 8.6.3. Now the boot fails with the following message:

    [BootFailedException: Boot failed: Umbraco cannot run. See Umbraco's log file for more details.
    
    -> Umbraco.Core.Exceptions.BootFailedException: Boot failed.
    
    -> System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei Umbraco.Web.Runtime.WebInitialComposer.<>c.<Compose>b__0_6(IFactory factory) in C:\Projekte\Umbraco-CMS\src\Umbraco.Web\Runtime\WebInitialComposer.cs:Zeile 119.
       bei Umbraco.Core.Composing.LightInject.LightInjectContainer.<>c__DisplayClass20_0`1.<Register>b__0(IServiceFactory f) in C:\Projekte\Umbraco-CMS\src\Umbraco.Core\Composing\LightInject\LightInjectContainer.cs:Zeile 172.
       bei DynamicMethod(Object[] )
       bei LightInject.ServiceContainer.<>c__DisplayClass150_0.<WrapAsFuncDelegate>b__0() in C:\projects\lightinject\src\LightInject\LightInject.cs:Zeile 3798.
    

    The message says, the failure occurs in WebInitialComposer.cs in line 119:

    118: var umbCtx = factory.GetInstance<UmbracoContext>();
    119: return new UmbracoHelper(umbCtx.IsFrontEndUmbracoRequest ? umbCtx.PublishedRequest?.PublishedContent : null,...
    

    factory.GetInstance() returns null.

    Now I set breakpoints into HybridUmbracoContextAccessor:

    public UmbracoContext UmbracoContext
    {
        get => Value;
        set => Value = value;
    }
    

    The breakpoint in the setter will never be hit. The getter is used and returns null.

    What could be the reason why the UmbracoContext is never set during boot?

    EDIT: UmbracoContextFactory.EnsureUmbracoContext(...) is never called.

    Mirko

  • mmaty 99 posts 228 karma points
    Sep 22, 2020 @ 11:25
    mmaty
    0

    Addition to this post:

    The error occurs while building all components of the ComponentCollection, while building the ExamineComponent.

    There is a lot of LightInject code executing to resolve the dependencies of ExamineComponent. And at the end we find ourselfes in a lambda expression which is the factory of UmbracoHelper:

    /// <inheritdoc />
    public void Register<TService>(Func<IFactory, TService> factory, Lifetime lifetime = Lifetime.Transient)
        where TService : class
    {
        Container.Register(f => factory(this), GetLifetime(lifetime));
    }
    

    TService is UmbracoHelper and factory(this) is the factory method registered to get the instance. Getting the instance involves the code shown in line 118 and 119 of WebInitialComposer.cs.

    For me it seems like a wrong initialization order, so that the UmbracoContext is resolved before it has been created.

    Does anybody have an idea, how this can happen?

  • mmaty 99 posts 228 karma points
    Sep 24, 2020 @ 08:53
    mmaty
    100

    I found the error. Just for the records:

    I registered a component with some dependencies. This dependencies had dependencies. And somewhere in the dependencies tree I had a class, having a constructor parameter of type UmbracoHelper.

    While UmbracoHelper will be well resolved in controller classes it is not available during the initialization of components. During initialization of components there exists no UmbracoContext.

Please Sign in or register to post replies

Write your reply to:

Draft