i think i’ve encountered a bug in EPiServer ContentType registration.
We are trying to write adapter for our legacy CMS controls. For this we register ContentTypes dynamically based on legacy code base. The ContentTypes we register are generic types, which works fine until we restart EPiServer and the content model has changed.
It seems that the AssemblyName isn’t correctly extracted from the fully qualified type name when the ContentTypeModelRegister analyzes the type model.
See ContentTypeModelRegister.GetContentTypeAssemblyName():
return new AssemblyName(modelTypeString.Substring(modelTypeString.IndexOf(",") + 1));
It simply splits the type string which is wrong for generic types.
For the content type “CmsControlConfigurationBlockData<HeadlineControl>” the following type name is stored:
EPiServer_CmsControlAdapter.CmsControlConfigurationBlockData`1[[DemoWebControls.HeadlineControl, DemoWebControls, Version=4.19.0.0, Culture=neutral, PublicKeyToken=null]], EPiServer_CmsControlAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Following exception is thrown:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) +0
System.Reflection.AssemblyName..ctor(String assemblyName) +77
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.GetContentTypeAssemblyName(ContentType contentType) +115
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.AnalyzeTypeModel(ContentTypeModel model, ContentType existingType) +46
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.<AnalyzeTypes>b__0(ContentTypeModel model) +79
System.Threading.Tasks.<>c__DisplayClass31_0`2.<ForEachWorker>b__0(Int32 i) +63
System.Threading.Tasks.<>c__DisplayClass17_0`1.<ForWorker>b__1() +930
System.Threading.Tasks.Task.InnerInvoke() +43
System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) +18
System.Threading.Tasks.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object ) +208
[AggregateException: One or more errors occurred.]
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +3632429
System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) +11537378
System.Threading.Tasks.Task.Wait() +15
System.Threading.Tasks.Parallel.ForWorker(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) +899
System.Threading.Tasks.Parallel.ForEachWorker(IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) +228
System.Threading.Tasks.Parallel.ForEachWorker(IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) +252
System.Threading.Tasks.Parallel.ForEach(IEnumerable`1 source, Action`1 body) +110
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.RunWithParallelsOptions(List`1 items, Action`1 action) +99
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelRegister.AnalyzeTypes() +63
EPiServer.DataAbstraction.RuntimeModel.ContentTypeModelScanner.Sync(Boolean commitChanges) +208
EPiServer_CmsControlAdapter.CmsControlAdapterInitializationModule.Initialize(InitializationEngine context) in C:\VisualStudio\CoreDevelopment\EPiServer_CmsMigration\EPiServer_CmsControlAdapter\CmsControlAdapterInitializationModule.cs:13
EPiServer.Framework.Initialization.<>c__DisplayClass5.<Initialize>b__4() +37
EPiServer.Framework.Initialization.ModuleNode.Execute(Action a, String key) +52
EPiServer.Framework.Initialization.ModuleNode.Initialize(InitializationEngine context) +105
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +169