InvalidOperationException: Collection was modified

  • Updated

This article describes an intermittent exception on startup caused by async registration of localization providers for modules because XForms translates text too early.  The error in stack trace is seen below.

[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +56
System.Collections.Generic.Enumerator.MoveNextRare() +14277518
EPiServer.Framework.Localization.ProviderBasedLocalizationService.LoadString(String[] normalizedKey, String originalKey, CultureInfo culture) +149
EPiServer.Framework.Localization.LocalizationService.TryGetStringByCulture(String originalKey, String[] normalizedKey, CultureInfo culture, CultureInfo fallbackCulture, String& localizedString) +88
EPiServer.Framework.Localization.LocalizationService.GetStringByCulture(String resourceKey, FallbackBehaviors fallbackBehavior, String fallback, CultureInfo culture) +321
EPiServer.Framework.Localization.LocalizationService.GetStringByCulture(String resourceKey, FallbackBehaviors fallbackBehavior, CultureInfo culture) +22
EPiServer.Initialization.Internal.XFormsInitialization.Initialize(InitializationEngine context) +271
EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +56
EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context) +123
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +425
[InitializationException: Initialize action failed for Initialize on class PiServer.Initialization.Internal.XFormsInitialization, EPiServer, Version=10.4.2.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +965
EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions) +192
EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction) +808
EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +190
EPiServer.Global..ctor() +84
ASP.global_asax..ctor() +48

This issue was resolved in EPiServer.CMS.Core 10.7.0.  Please update to this package or later which can be found here.