Problems with add-ons and StructureMap

Vote:
 

We're using constructor dependency injection in our EPiServer site which has worked really well. Up to now, that is... We have started to install a few add-ons to the site and for some of them, e.g. SiteAttention, we're getting initialization problems. This is a frequent type of message:

[ArgumentException: Unable to find a module by assembly 'SiteAttentionModule, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
Parameter name: moduleAssembly]
   EPiServer.Shell.Paths.ToResource(Assembly moduleAssembly, String moduleRelativeResourcePath) +322
   EPiServer.PlugIn.GuiPlugInAttribute.ResolvePathInternal(String path, ResolvePathDelegate resolvePathDelegate) +51

[TargetInvocationException: Property accessor 'Url' on object 'EPiServer.PlugIn.GuiPlugInAttribute' threw the following exception:'Unable to find a module by assembly 'SiteAttentionModule, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
Parameter name: moduleAssembly']
   System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +525
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +104
   System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) +95
   ASP.webmgmt_cms_admin_menu_aspx.__DataBind__control37(Object sender, EventArgs e) in C:\code\Scandic_Xena\Scandic.Xena.Web\webmgmt\CMS\Admin\menu.aspx:160
   System.Web.UI.Control.OnDataBinding(EventArgs e) +99
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
   System.Web.UI.Control.DataBindChildren() +252
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +195
   System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +174
   System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +625
   System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +82
   EPiServer.UI.Admin.Menu.CreatePluginEntries() +190
   EPiServer.UI.Admin.Menu.OnLoad(EventArgs e) +61
   System.Web.UI.Control.LoadRecursive() +68
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8383

In the case of SiteAttention we get this in the menu of the Admin mode (/webmgmt/CMS/Admin/Menu.aspx), the rest of the site works fine. We're having similar problems with EPiServer Languages, but as that error seems more complicated I think it might be easier to solve SiteAttention first...

Our dependency resolver looks like this:

[ModuleDependency(typeof(ServiceContainerInitialization))]
[InitializableModule]
public class StructureMapConfig : IConfigurableModule
{
public void Initialize(InitializationEngine context) {}

public void Uninitialize(InitializationEngine context) {}

public void Preload(string[] parameters) {}

public void ConfigureContainer(ServiceConfigurationContext context)
{
var container = context.Container;

// MVC
DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));

// Web Api
GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container);

ConfigureMappings(container);
}

private static void ConfigureMappings(IContainer container)
{
// Automatically map interface to instance using standard convenetion of "IClassName" => instance of "ClassName"
container.Configure(c => c.Scan(assemblyScanner =>
{
assemblyScanner.TheCallingAssembly();
assemblyScanner.WithDefaultConventions();
}));

// Explicit mappings of exceptions from the convention
container.Configure(c => c.For().Use());
container.Configure(c => c.For().Use());
container.Configure(c => c.For().Use());
}
}

Any ideas of what the problem might be is greatly appriecated! This is starting to get to me...

Cheers!

Emil

#115317
Jan 13, 2015 17:04
Vote:
 

Why do you think it's related with StructureMap? For me it seems that SiteAttention is failing to register itself in ModuleTable collection (or most probably EPiServer is failing to discover that module and register it in ModulesTable). Can you check access, permissions, etc.? Are other AddOns working?

#115356
Jan 13, 2015 22:12
Vote:
 

Hi Valdis,

Now that you mention it, it is possible that it's unrelated to StructureMap. For the other problematic add-on (EPiServer Languages) StructureMap was in the exception stack trace but it's not in this case.

I have decompiled the EPiServer dll:s and the exception comes from EPiServer.Shell.Paths, a property called ToResource:

public static string ToResource(Assembly moduleAssembly, string moduleRelativeResourcePath)
{
    ShellModule shellModule;
    if (moduleAssembly == null)
    {
        throw new ArgumentNullException("moduleAssembly", "Unable to resolve path to module resources folder by null assembly.");
    }
    if (!ServiceLocator.Current.GetInstance<ModuleTable>().TryGetModule(moduleAssembly, out shellModule))
    {
        throw new ArgumentException(string.Concat("Unable to find a module by assembly '", moduleAssembly, "'"), "moduleAssembly");
    }
    return ModuleTable.ResolvePath(shellModule, moduleRelativeResourcePath);
}

So as you point out, it seems that the Add-on is indeed missing from ModuleTable. I'll continue to research how this may happen.

Emil

#115361
Edited, Jan 14, 2015 0:41
Vote:
 

Can you post Language AddOn stracktrace? What about other addons?

#115362
Jan 14, 2015 0:44
Vote:
 

Sure, here we go:

[ArgumentException: Unable to find a module by assembly 'EPiServer.Labs.LanguageManager, Version=1.1.1.7514, Culture=neutral, PublicKeyToken=null'
Parameter name: moduleAssembly]
   EPiServer.Shell.Paths.ToResource(Assembly moduleAssembly, String moduleRelativeResourcePath) +322
   EPiServer.Labs.LanguageManager.LanguageManagerComponent..ctor() +202

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +147
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +104
   System.Activator.CreateInstance(Type type) +12
   EPiServer.Shell.ViewComposition.ComponentAttribute.CreateComponentDefinition(Type attributedType) +99
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +229
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +538
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +73
   EPiServer.Shell.ViewComposition.AttributedComponentProvider.GetComponentDefinitions() +310
   EPiServer.Shell.ViewComposition.ComponentManager.ListAll() +256
   EPiServer.Shell.ViewComposition.DefaultViewManager..ctor(IEnumerable`1 viewProviders, IEnumerable`1 viewTransformers, IComponentManager componentManager) +44
   lambda_method(Closure , IArguments ) +236
   StructureMap.Construction.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\BuilderCompiler.cs:56
   StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:233

[StructureMapException: StructureMap Exception Code:  207
Internal exception while creating Instance '3e3d3525-c286-4099-baa9-be49757b1743' of PluginType EPiServer.Shell.ViewComposition.IViewManager.  Check the inner exception for more details.]
   StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:245
   StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:103
   StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:69
   StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:27
   StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:176
   StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:103
   StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:69
   StructureMap.Pipeline.ConstructorInstance.Get(String propertyName, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:79
   lambda_method(Closure , IArguments ) +59
   StructureMap.Construction.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\BuilderCompiler.cs:56
   StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:237
   StructureMap.Pipeline.SmartInstance`1.build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\SmartInstance.cs:156
   StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:103
   StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:69
   StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:27
   StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:176
   StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:103
   StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:69
   StructureMap.Pipeline.ConstructorInstance.Get(String propertyName, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:79
   lambda_method(Closure , IArguments ) +118
   StructureMap.Construction.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\BuilderCompiler.cs:56
   StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:237
   StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:103
   StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:69
   StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:27
   StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:176
   EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +55

[ActivationException: Activation error occurred while trying to get instance of type EPiDashboardController, key ""]
   EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +156
   EPiServer.Shell.Web.Mvc.ModuleControllerFactory.CreateController(RequestContext requestContext, String controllerName) +347
   EPiServer.Shell.Web.Mvc.ModuleMvcHandler.ProcessRequestInit(HttpContextBase httpContext) +104
   EPiServer.Shell.Web.Mvc.ModuleMvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +17
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +932
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159

Thinking about it, I suspect the problem is probably very similar to the one for SiteAttention although the stack trace is much deeper this time.

/Emil

#115424
Jan 15, 2015 0:05
Vote:
 

Seems like the problem is exactly the same. Just this time creation of type happens to be through StructureMap.

#115429
Jan 15, 2015 6:06
Vote:
 

This is really fun to come back to the topic where you have commented a while ago :)

Anyway, just got a support case with excatly the same symptons as here. 7.5 site with language manager addon installed. Site failed to load.

After a while debugging and tracing found out that explicitly version 1.1.1.7514 has a small issue with packaging and modules.config file.

Problem is that modules.config file is not part of addon .zip package file (EPiServer.Labs.LanguageManager.zip). It's added to the root under modules/_protected/EPiServer.Labs.LanguageManager. If you modify .zip file and copy modules.config file just directly into .zip file. Site loads up, and EPiServer is able to find this module by assembly. Under the hood: EPiServer was able to find module and register it in its internal modules table, but there was no modules.config file for this module (because EPiServer looks under /cms/EPiServer.Labs.LanguageManager path that mapped via ModuleZipVirtualFileProvider or similar type). If EPiServer is not able to find this module.config file, module is still registered, but associated assembly is not added to the module list. Basically EPiServer is losing this fragment:

  <assemblies>
    <add assembly="EPiServer.Labs.LanguageManager" />
  </assemblies>

Next thing was -> gadget was now available for editors, but it was empty. Gadget content was not loaded.

After grepping log files, found out that EPiServer was not able to find /cms/EPiServer.Labs.LanguageManager/EPiServer.LanguageManager.config file. IO excpetion.

Looking at source code found out that module is mapping virtual file from module relative path - basically skipping zip virtual file provider and asking IIS directly to return this file path in order to open it up and read module settings. Of course IIS can return direct mapping from /cms/.. to actual physical file location. But this fails because IIS does not know anything about EPiServer virtual directory mapping and setup.

Quick workaround is to copy EPiServer.LanguageManager.config file to /cms/ directory in your website root.

/cms/ of course may varry depending on your EPiServer setup. /episerver/, /cms/ or any other configured directory.

#140420
Oct 19, 2015 21:00
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.