Solving EPiServer.Framework.Initialization. InitializationEngine: Initialize action failed for ‘Initialize on class EPiServer.Enterprise.Internal. EnterpriseInitialization,

Recently I was upgrading an Episerver project to v10.9.0 using nuget package manager. I also upgraded the database by entering Update-EPiDatabase -verbose:$true in the nuget package manager console in visual studio.

When trying to run the website I got a http 500 error. In the logs I could see the stacktracke below.

ERROR EPiServer.Framework.Initialization.InitializationEngine: Initialize action failed for 'Initialize on class EPiServer.Enterprise.Internal.EnterpriseInitialization, EPiServer.Enterprise, Version=10.9.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'
EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type PropertyContentReferenceListTransform, key "" ---> StructureMap.Building.StructureMapBuildException: Error while building type EPiServer.Core.Transfer.Internal.DependentContentTransfer. See the inner exception for details
1.) new DependentContentTransfer(*Default of IContentLoader*, *Default of IContentTypeRepository*, *Default of IPermanentLinkMapper*, *Default of ISiteDefinitionRepository*, *Default of ContentRootService*)
2.) EPiServer.Core.Transfer.Internal.DependentContentTransfer
3.) Instance of EPiServer.Core.Transfer.IDependentContentTransfer (EPiServer.Core.Transfer.Internal.DependentContentTransfer)
4.) new PropertyContentReferenceListTransform(*Default of IPermanentLinkMapper*, *Default of IContentLoader*, *Default of IDependentContentTransfer*)
5.) EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
6.) Instance of EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
7.) Container.GetInstance(EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform)

… full stack trace at the end of the post.

The solution

In the connection string the MultipleActiveResultSets=True was missing. Once I added it, the site was working again.
<add name="EPiServerDB" connectionString="Data Source=XXXX;Initial Catalog=XXXX;Integrated Security=False;User ID=XXXX;Password=XXXX;Connect Timeout=30;<strong>MultipleActiveResultSets=True</strong>" providerName="System.Data.SqlClient" /></pre>

The full stacktrace

This is the full stacktrace of the error:

ERROR EPiServer.Framework.Initialization.InitializationEngine: Initialize action failed for 'Initialize on class EPiServer.Enterprise.Internal.EnterpriseInitialization, EPiServer.Enterprise, Version=10.9.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'
EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type PropertyContentReferenceListTransform, key "" ---> StructureMap.Building.StructureMapBuildException: Error while building type EPiServer.Core.Transfer.Internal.DependentContentTransfer. See the inner exception for details
1.) new DependentContentTransfer(*Default of IContentLoader*, *Default of IContentTypeRepository*, *Default of IPermanentLinkMapper*, *Default of ISiteDefinitionRepository*, *Default of ContentRootService*)
2.) EPiServer.Core.Transfer.Internal.DependentContentTransfer
3.) Instance of EPiServer.Core.Transfer.IDependentContentTransfer (EPiServer.Core.Transfer.Internal.DependentContentTransfer)
4.) new PropertyContentReferenceListTransform(*Default of IPermanentLinkMapper*, *Default of IContentLoader*, *Default of IDependentContentTransfer*)
5.) EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
6.) Instance of EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
7.) Container.GetInstance(EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform)
---> System.TypeInitializationException: The type initializer for 'EPiServer.Web.SiteDefinition' threw an exception. ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at EPiServer.DataAccess.Internal.ContentListDB.b__8_0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass31_0`1.b__0()
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
at EPiServer.DataAbstraction.Internal.DefaultContentRootRepository.EnsureSystemRoots()
at EPiServer.DataAbstraction.Internal.DefaultContentRootRepository.Load(String rootName)
at EPiServer.Web.SystemDefinition.get_Current()
at EPiServer.Web.SiteDefinition.get_SiteAssetsRoot()
at EPiServer.Web.SiteDefinition.MakeReadOnly()
at EPiServer.Web.SiteDefinition..cctor()
--- End of inner exception stack trace ---
at EPiServer.DataAccess.Internal.SiteDefinitionDB.SiteDefinitionFromReader(IDataRecord r)
at EPiServer.DataAccess.Internal.SiteDefinitionDB.b__4_0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass31_0`1.b__0()
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
at EPiServer.Web.Internal.DefaultSiteDefinitionRepository.List()
at EPiServer.Core.Transfer.Internal.DependentContentTransfer..ctor(IContentLoader contentLoader, IContentTypeRepository contentTypeRepository, IPermanentLinkMapper permanentLinkMapper, ISiteDefinitionRepository siteRepository, ContentRootService contentRootService)
at lambda_method(Closure , IBuildSession , IContext )
--- End of inner exception stack trace ---
at lambda_method(Closure , IBuildSession , IContext )
at StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\Building\BuildPlan.cs:line 151
at StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\SessionCache.cs:line 93
at StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\SessionCache.cs:line 68
at StructureMap.Container.GetInstance(Type pluginType) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\Container.cs:line 337
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at EPiServer.Enterprise.Internal.EnterpriseInitialization.RegisterImportingEventHandlers(IDataImportEvents importerEvents, IServiceLocator factory)
at EPiServer.Enterprise.Internal.EnterpriseInitialization.Initialize(InitializationEngine context)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context)
at EPiServer.Framework.Initialization.InitializationEngine.InitializeModules()
EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type PropertyContentReferenceListTransform, key "" ---> StructureMap.Building.StructureMapBuildException: Error while building type EPiServer.Core.Transfer.Internal.DependentContentTransfer. See the inner exception for details
1.) new DependentContentTransfer(*Default of IContentLoader*, *Default of IContentTypeRepository*, *Default of IPermanentLinkMapper*, *Default of ISiteDefinitionRepository*, *Default of ContentRootService*)
2.) EPiServer.Core.Transfer.Internal.DependentContentTransfer
3.) Instance of EPiServer.Core.Transfer.IDependentContentTransfer (EPiServer.Core.Transfer.Internal.DependentContentTransfer)
4.) new PropertyContentReferenceListTransform(*Default of IPermanentLinkMapper*, *Default of IContentLoader*, *Default of IDependentContentTransfer*)
5.) EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
6.) Instance of EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform
7.) Container.GetInstance(EPiServer.Core.Transfer.Internal.PropertyContentReferenceListTransform)
---> System.TypeInitializationException: The type initializer for 'EPiServer.Web.SiteDefinition' threw an exception. ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at EPiServer.DataAccess.Internal.ContentListDB.b__8_0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass31_0`1.b__0()
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
at EPiServer.DataAbstraction.Internal.DefaultContentRootRepository.EnsureSystemRoots()
at EPiServer.DataAbstraction.Internal.DefaultContentRootRepository.Load(String rootName)
at EPiServer.Web.SystemDefinition.get_Current()
at EPiServer.Web.SiteDefinition.get_SiteAssetsRoot()
at EPiServer.Web.SiteDefinition.MakeReadOnly()
at EPiServer.Web.SiteDefinition..cctor()
--- End of inner exception stack trace ---
at EPiServer.DataAccess.Internal.SiteDefinitionDB.SiteDefinitionFromReader(IDataRecord r)
at EPiServer.DataAccess.Internal.SiteDefinitionDB.b__4_0()
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass31_0`1.b__0()
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
at EPiServer.Web.Internal.DefaultSiteDefinitionRepository.List()
at EPiServer.Core.Transfer.Internal.DependentContentTransfer..ctor(IContentLoader contentLoader, IContentTypeRepository contentTypeRepository, IPermanentLinkMapper permanentLinkMapper, ISiteDefinitionRepository siteRepository, ContentRootService contentRootService)
at lambda_method(Closure , IBuildSession , IContext )
--- End of inner exception stack trace ---
at lambda_method(Closure , IBuildSession , IContext )
at StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\Building\BuildPlan.cs:line 151
at StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\SessionCache.cs:line 93
at StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\SessionCache.cs:line 68
at StructureMap.Container.GetInstance(Type pluginType) in c:\BuildAgent\work\a395dbde6b793293\src\StructureMap\Container.cs:line 337
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at EPiServer.Enterprise.Internal.EnterpriseInitialization.RegisterImportingEventHandlers(IDataImportEvents importerEvents, IServiceLocator factory)
at EPiServer.Enterprise.Internal.EnterpriseInitialization.Initialize(InitializationEngine context)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key)
at EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context)
at EPiServer.Framework.Initialization.InitializationEngine.InitializeModules()

Sitecore Project Architecture – Part 1 Structure of Sitecore Tree

We will have a look at how to organize a multi site solution in Sitecore. In this part we’ll focus on the Structure in Sitecore, in a later post I will talk about the structure in Visual Studio.

There are multiple ways of structuring your solution and it all depends on the project requirements , best practices and your preferences. So feel free to drop your approach in the comments and mention why it works for you.

The basic approach is to have a Global folder and Site specific folders: “Site1”, “Site2”, …

The Global folder will contain templates and items that are not site specific or can be shared by multiple sites.

The Site specific folders will contain templates and items that are specific for that site.

Besides avoiding chaos tree horror and angry content editors, a good structure will also help you to apply more fine grained security settings as you can apply different security settings on each folder and therefore restrict access to certain folders for certain roles and users.

There are 4 main areas that can benefit from using the Global and Site specific folders: Content, Layout, Media Library and Templates.

sitecore_structure

Content

sitecore_structure_content

In the Global folder you can store

  • item to configure the whole platform
  • global dictionary (“buy now” call to action can be used on all the sites)
  • (datasource) items that can be referenced by all sites: you can have all your office items in the global folder and use them the sites you like.

In the Site specific folders you can store

  • item to configure the specific site
  • dictionary that only contains site specific translations
  • (datasource) items specific for this site

Layout

sitecore_structure_layout

It’s a good idea to replicate the same structure in the file system as this will avoid confusion and flexibility to deploy site specific components. So check the path field when you add a layout/rendering/sublayout.

Media Library

sitecore_structure_media_library

Templates

sitecore_structure_templates

The “YourClientName” folder is useful to differentiate templates that you created and templates folders that are automatically created when you install certain Sitecore modules

In the Global folder you can create templates (often for datasource items) used by components that can be used in all the sites.

In the Global/Fields folder you can create basic building blocks: each templates has just a few fields. A lot of templates need “description” field, so instead of adding a description field to each templates you can use Sitecore’s inheritance model. Even if your building block only contains 1 field, it means that the field will be consistently the same everywhere you inherit it. This is useful to avoid situations where you would name your field “summary” in one template and “short description” in another template and confuse content editors.
It will also simplify your (possibly code generated) models.

There is a nice best practices webinar that also talks about Sitecore structure:

Feel free to drop your approach, comments and feedback.