Issue when trying to get named service instances from EpiServer 11.x


I am responsible for a customer site that we want to upgrade from Epi v.10.10.0 to newest 11.x version.

We have upgraded as many components to as recent versions as  as possible, including EPiServer.Location.StructureMap.

The main problem we are facing is in fact connected to StructureMap, 

  • IServiceLocator no longer supports named instances. The specific implementation in EPiServer.ServiceLocation.StructureMap supports named instances.

We have a lot of this type of code in the existing application:

var myObj= ServiceLocator.Current.GetInstance();

However, this is failing with the following message:

An exception of type 'EPiServer.ServiceLocation.ActivationException' occurred in EPiServer.Framework.dll but was not handled in user code

Additional information: Activation error occurred while trying to get instance of type IMemberShipLoader, key ""

This code worked perfectly well in Epi 10.

How would we go about obtaining the same result in Epi 11? The release notes from EPiServer tell us "The specific implementation in EPiServer.ServiceLocation.StructureMap supports named instances.", but which calls are we actualy supposed to make?

Any help would be appreciated.

Below I have also attached the packages.config for the main project.

Edited, Mar 20, 2018 15:09

So if you have registered an instance as a named instance in StructureMap, e.g like:

 public void ConfigureContainer(ServiceConfigurationContext context)
            context.StructureMap().Configure(c =>

then to receive your named instance using ServiceLocator.Current you need to cast it to StructureMapServiceLocator, like:

(ServiceLocator.Current as StructureMapServiceLocator).GetInstance<IMyInterface>("myKey");

Mar 22, 2018 15:10
* 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.