Try our conversational search powered by Generative AI!

StructureMap problem


Hi, I am having problems with structuremap again.

In Global.asax, I have an override of RegisterRoutes:

protected override void RegisterRoutes(RouteCollection routes)
            ObjectFactory.BuildUp(this); // with or without this line, the next line breaks

            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); // breaks here


I have a configurable module, that gets called first (before RegisterRoutes):

    public class DependencyResolverInitialization : IConfigurableModule
        public void ConfigureContainer(ServiceConfigurationContext context)
            IContainer container = IoC.Initialize();
            DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container);


   I have referenced StructureMap from this location:


Now, in web.config, I am having this commented out:

        <assemblyIdentity name="StructureMap" publicKeyToken="e60ad81abae3c223" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />

When I use ObjectFactory.WhatDoIHave();, I get the following error:

The type 'StructureMap.ObjectFactory' exists in both 'StructureMap.dll' and 'StructureMap.dll'

If I uncomment the web.config part, I get:

Missing requested Instance property "NamedIndexingService" for InstanceKey "6b1c69a3-1eba-470c-95fb-492045313561"

For the version with commented out dependentAssembly in web.config, I can comment out the problematic part of code, run the app, uncomment it and it works. I would really like a real solution instead of this tweak.

Any clues on what I'm doing wrong?



Jun 12, 2013 14:54

Hi Marija!

We need the versionredirect in order for the EPiServer core to load the correct version. Potentially you can try redirecting to a newer version given that it's backwards compatible with the old version. Removing the redirect will otherwise give you two different versions loaded in the same app domain which usually means trouble.

Jun 12, 2013 16:47

Hi, thx, but in that case I get:

Missing requested Instance property "NamedIndexingService" for InstanceKey "1c0b201e-8c75-49d0-90ce-2c9c25305f2a"

Edited, Jun 13, 2013 9:37

I have figured out that the line EndsWith("Service") makes the problem with NamedIndexingService.

ObjectFactory.Configure(x =>
                    x.Scan(s =>

                        policy => policy.NameMatches(name => name.EndsWith("Service")));

Without it, the exception doesn't occur.

I have removed it, since it is a part of a default convension and in the module public class ContentInitializableModule : IInitializableModule that subscibes to content events, I am manually getting the instance of my service class in public void Initialize(InitializationEngine context):

_contentService = ObjectFactory.GetInstance<IContentService>();

Edited, Jun 13, 2013 12:38
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.