Dependency Injection - when one service relies on another and blows up the boot
I'm struggling with a weird issue that is causing the dreaded "HTTP Error 500.30 - ASP.NET Core app failed to start" message. Checking the Windows Event Viewer - the specific error is "System.InvalidOperationException: Wasn't able to get an UmbracoContext"
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Wasn't able to get an UmbracoContext
at Umbraco.Extensions.UmbracoContextAccessorExtensions.GetRequiredUmbracoContext(IUmbracoContextAccessor umbracoContextAccessor)
at Umbraco.Cms.Infrastructure.DependencyInjection.UmbracoBuilderExtensions.<>c.<AddCoreInitialServices>b__0_11(IServiceProvider factory)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetServices[T](IServiceProvider provider)
at Umbraco.Cms.Core.Events.NotificationHandlerWrapperImpl`1.Handle(INotification notification, ServiceFactory serviceFactory, Action`2 publish)
at Umbraco.Cms.Core.Events.EventAggregator.PublishNotification(INotification notification)
at Umbraco.Cms.Core.Events.EventAggregator.PublishAsync[TNotification](TNotification notification, CancellationToken cancellationToken)
at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.StartAsync(CancellationToken cancellationToken, Boolean isRestarting)
at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at UmbracoProject.Program.Main(String[] args) in C:\Users\Heather\WEBS\Clients\LOYD\American Regent\sourcecode-10\src\UmbracoProject\Program.cs:line 6
What seems to be causing the error is a DI service I am adding via the Startup.cs which relies on another injected service.
Since loading the SiteHelperService via the Startup file works fine, I just don't understand why it causes an issue when loaded into the other service.
My constructors are pretty straightforward - basically storing those injected services to local fields...
What I did notice, is that if I remove the interface IPageRenderer from BaseModelPageRenderer, the startup error doesn't occur.
ex:
public class BaseModelPageRenderer : IPageRenderer
to:
public class BaseModelPageRenderer
so it seems to be something having to do with the IPageRenderer...
This is all used in conjunction with a Full Text Search Indexer, and the new class is supposed to provide custom page rendering for the indexer to use, rather than an HTTP request. I will likely need to dig into that codebase and figure out where/when that is getting loaded, and perhaps causing the missing Context issue.
Dependency Injection - when one service relies on another and blows up the boot
I'm struggling with a weird issue that is causing the dreaded "HTTP Error 500.30 - ASP.NET Core app failed to start" message. Checking the Windows Event Viewer - the specific error is "System.InvalidOperationException: Wasn't able to get an UmbracoContext"
What seems to be causing the error is a DI service I am adding via the Startup.cs which relies on another injected service.
Here is a simplified example of what I mean:
Startup.cs
BaseModelPageRenderer relies upon SiteHelperService:
BaseModelPageRenderer.cs
SiteHelperService.cs
If I comment-out the line in 'Startup':
Then the site will load just fine.
OR if I leave that in, and instead comment out this bit in 'BaseModelPageRenderer':
Then the site will load just fine.
Since loading the SiteHelperService via the Startup file works fine, I just don't understand why it causes an issue when loaded into the other service.
Hi Heather
Generally this should be a problem. I tried setting up similar services, and have no problem booting up Umbraco.
Couldn't it be something that you're doing in one of the constructors?
Hi Anders!
My constructors are pretty straightforward - basically storing those injected services to local fields...
What I did notice, is that if I remove the interface
IPageRenderer
from BaseModelPageRenderer, the startup error doesn't occur.ex:
public class BaseModelPageRenderer : IPageRenderer
to:
public class BaseModelPageRenderer
so it seems to be something having to do with the
IPageRenderer
...This is all used in conjunction with a Full Text Search Indexer, and the new class is supposed to provide custom page rendering for the indexer to use, rather than an HTTP request. I will likely need to dig into that codebase and figure out where/when that is getting loaded, and perhaps causing the missing Context issue.
Thanks for testing and replying!
is working on a reply...