ShellContextFactory: ComponentNotRegisteredException

Topics: Administration, Core, General, Troubleshooting
Apr 15, 2012 at 3:56 PM
Edited Apr 15, 2012 at 4:19 PM

Hello,

we are experiencing quite unusual problems. We have build and deployed a site with Orchard (Orchard 1.3, with VS2010, running under IIS7.5 and SQLExpress). The site ran smoothly until about two days ago. Without us having (consciously) changed anything in the application or the database, we now get the following exception:

 

Server Error in '/' Application.
The requested service 'Orchard.IWorkContextAccessor' has not been registered.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'Orchard.IWorkContextAccessor' has not been registered.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ComponentNotRegisteredException: The requested service 'Orchard.IWorkContextAccessor' has not been registered.]
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, Service service, IEnumerable`1 parameters) +562
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +117
   Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings) in c:\Projects\Discoverize\src\Orchard\Environment\ShellBuilders\ShellContextFactory.cs:61
   Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:133
   Orchard.Environment.DefaultOrchardHost.BuildCurrent() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:103
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.Initialize() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:67
   Orchard.Web.MvcApplication.HostInitialization(HttpApplication application) in c:\Projects\Discoverize\src\Orchard.Web\Global.asax.cs:51
   Orchard.WarmupStarter.<>c__DisplayClass3.<LaunchStartupThread>b__2(Object state) in c:\Projects\Discoverize\src\Orchard.Startup\Starter.cs:89

[ApplicationException: Error during application initialization]
   Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in c:\Projects\Discoverize\src\Orchard.Startup\Starter.cs:63

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +152
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +403
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +74
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +163
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +354


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.547 

Sometimes I get the following, slightly different exception:

Exception Details: Autofac.Core.DependencyResolutionException: None of the constructors found with policy 'Autofac.Core.Activators.Reflection.BindingFlagsConstructorFinder' on type 'Orchard.Environment.DefaultOrchardShell' can be invoked with the available services and parameters:
Constructor 'Void .ctor(System.Func`1[Autofac.Features.OwnedInstances.Owned`1[Orchard.Environment.IOrchardShellEvents]], System.Collections.Generic.IEnumerable`1[Orchard.Mvc.Routes.IRouteProvider], Orchard.Mvc.Routes.IRoutePublisher, System.Collections.Generic.IEnumerable`1[Orchard.Mvc.ModelBinders.IModelBinderProvider], Orchard.Mvc.ModelBinders.IModelBinderPublisher)' parameter resolution failed at parameter 'Orchard.Mvc.Routes.IRoutePublisher routePublisher'.

Stack Trace:

[DependencyResolutionException: None of the constructors found with policy 'Autofac.Core.Activators.Reflection.BindingFlagsConstructorFinder' on type 'Orchard.Environment.DefaultOrchardShell' can be invoked with the available services and parameters:
Constructor 'Void .ctor(System.Func`1[Autofac.Features.OwnedInstances.Owned`1[Orchard.Environment.IOrchardShellEvents]], System.Collections.Generic.IEnumerable`1[Orchard.Mvc.Routes.IRouteProvider], Orchard.Mvc.Routes.IRoutePublisher, System.Collections.Generic.IEnumerable`1[Orchard.Mvc.ModelBinders.IModelBinderProvider], Orchard.Mvc.ModelBinders.IModelBinderPublisher)' parameter resolution failed at parameter 'Orchard.Mvc.Routes.IRoutePublisher routePublisher'.]
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +578
   Autofac.Core.Resolving.ComponentActivation.Activate(IEnumerable`1 parameters) +89
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +122
   Autofac.Core.Resolving.ComponentActivation.Execute(IEnumerable`1 parameters) +255
   Autofac.Core.Resolving.ResolveOperation.Resolve(ISharingLifetimeScope activationScope, IComponentRegistration registration, IEnumerable`1 parameters) +246
   Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +15
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +74
   Autofac.Core.Resolving.ComponentActivation.Activate(IEnumerable`1 parameters) +89
   Autofac.Core.Resolving.ComponentActivation.Execute(IEnumerable`1 parameters) +141
   Autofac.Core.Resolving.ResolveOperation.Resolve(ISharingLifetimeScope activationScope, IComponentRegistration registration, IEnumerable`1 parameters) +246
   Autofac.Core.Lifetime.LifetimeScope.Resolve(IComponentRegistration registration, IEnumerable`1 parameters) +276
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, Service service, IEnumerable`1 parameters) +221
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +117
   Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings) in c:\Projects\Discoverize\src\Orchard\Environment\ShellBuilders\ShellContextFactory.cs:78
   Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:133
   Orchard.Environment.DefaultOrchardHost.BuildCurrent() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:103
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.Initialize() in c:\Projects\Discoverize\src\Orchard\Environment\DefaultOrchardHost.cs:67
   Orchard.Web.MvcApplication.HostInitialization(HttpApplication application) in c:\Projects\Discoverize\src\Orchard.Web\Global.asax.cs:51
   Orchard.WarmupStarter.<>c__DisplayClass3.<LaunchStartupThread>b__2(Object state) in c:\Projects\Discoverize\src\Orchard.Startup\Starter.cs:89

[ApplicationException: Error during application initialization]
   Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in c:\Projects\Discoverize\src\Orchard.Startup\Starter.cs:63

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +152
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +403
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +74
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +163
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +354

All these errors seem to originate in the ShellContextFactory, or Autofac is not working properly. I looked at the code, but cannot see why the Service Orchard.IWorkContextAccessor should not have been registered.

I tried a few things to remedy the problem: Restore the DB from a few days earlier, Delete Dependencies directory and cache file, restarting the application. It all did not help. Strange thing is that our stage application (which we do not have changed either after it ran smoothly) has the same symptoms.

Can somebody point me in a direction on how we could solve this problem?

Coordinator
Apr 16, 2012 at 12:41 AM

You must have changed something, maybe installed a new version of a module that is not compatible with 1.3? Maybe check the timestamps on deployed files?

Apr 16, 2012 at 10:19 AM
Edited Apr 16, 2012 at 10:20 AM

That is the strange thing: The only files that have been changed since it ran error-free, are files in the App_Data folder.

We already tried to delete the Dependencies folder and the cache.dat file. Also we tried to delete the "..\App_Data\Sites\Default\mappings.bin" file. Apart from that the only files that changed, are the log files and a settings XML-file in the "..\App_Data\Sites\Default\" folder (which I can rule out as the source of the error).

That is why we are so confused.

Could it have to do with something outside the application itself? Yet, we do have the latest updates for the .NET framework.

Apr 16, 2012 at 5:10 PM

We could get it back running. We created a new Orchard instance from a recipe with an empty database, and then restored the database from a backup.

The buggy and bugfree versions do differ quite a bit (many files and folders not in the bugfree version). We will look through it, and hope to find the cause for this issue (and then post it here).

Apr 18, 2012 at 10:42 AM

After testing out quite a few combinations of versions of our application with different backups of the database, it seems like the fault was due to corrupt data. Likely the fault was initiated due to renaming a Feature + Module and everything that comes with it. (It also just happened that we renamed the feature to an already existing name.)