diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 978c4f2906..d08d431221 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -94,7 +94,7 @@ namespace Umbraco.Core.Runtime composition.RegisterUnique(databaseFactory); composition.RegisterUnique(_ => databaseFactory.SqlContext); composition.RegisterUnique(typeLoader); - composition.RegisterUnique(_state); + composition.RegisterUnique(_state); // register runtime-level services Compose(composition); @@ -141,6 +141,18 @@ namespace Umbraco.Core.Runtime _state.BootFailedException = bfe; bootTimer.Fail(exception: bfe); // be sure to log the exception - even if we repeat ourselves + // if something goes wrong above, we may end up with no factory + // meaning nothing can get the runtime state, etc - so let's try + // to make sure we have a factory + if (_factory == null) + { + try + { + _factory = Current.Factory = composition.CreateFactory(); + } + catch { /* yea */ } + } + // throwing here can cause w3wp to hard-crash and we want to avoid it. // instead, we're logging the exception and setting level to BootFailed. // various parts of Umbraco such as UmbracoModule and UmbracoDefaultOwinStartup