Cannot create an instance of Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewDefinitionElement because it is an abstract class.
I've created a pluggable module based on the example Jobs module. I installed it and it worked fine. I then added an extra field to it and as soon as I try and access the content area I get the message below. Any idea what is going wrong?
Server Error in '/' Application.Cannot create an instance of Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewDefinitionElement because it is an abstract class.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MemberAccessException: Cannot create an instance of Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewDefinitionElement because it is an abstract class.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace: [MemberAccessException: Cannot create an instance of Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewDefinitionElement because it is an abstract class.] System.Reflection.RuntimeConstructorInfo.CheckCanCreateInstance(Type declaringType, Boolean isVarArg) +9587582 System.Reflection.RuntimeConstructorInfo.ThrowNoInvokeException() +56 System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +9637248 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136 System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111 System.Activator.CreateInstance(Type type, Object[] args) +19 Telerik.Sitefinity.Configuration.ConfigUtils.CreateInstance(Type baseType, Type actualType, Object[] args) +236 Telerik.Sitefinity.Configuration.ConfigUtils.CreateInstance(Type actualType, Object[] args) +103 Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.CreateNew(Type type) +132 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadCollectionElement(ConfigElementCollection collection, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo) +1326 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo, Boolean isNew, Boolean validateTagName) +398 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadPropertyElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo) +478 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo, Boolean isNew, Boolean validateTagName) +435 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadCollectionElement(ConfigElementCollection collection, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo) +1469 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo, Boolean isNew, Boolean validateTagName) +398 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadPropertyElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo) +478 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, UpgradingInfo upgradingInfo, Boolean isNew, Boolean validateTagName) +435 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSectionFromReader(ConfigSection section, XmlReader reader, ConfigPolicyHandler policyHandler, String policyName, Boolean checkForUpgrade, UpgradingInfo& upgradingInfo) +422 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSectionFromFile(ConfigSection section, ConfigPolicyHandler policyHandler, String policyName, Boolean withUpgrade) +136 Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSection(ConfigSection section, ConfigPolicyHandler policyHandler, String policyName) +126 Telerik.Sitefinity.Configuration.ConfigSection.Initialize(ConfigProvider provider, ConfigPolicyHandler policyHandler, String policyName, Boolean singlePolicy) +260 Telerik.Sitefinity.Configuration.ConfigSection.Initialize(ConfigProvider provider) +45 Telerik.Sitefinity.Configuration.Config.GetConfigSection(String name) +362 Telerik.Sitefinity.Configuration.Config.GetByPath(String path) +148 Telerik.Sitefinity.Configuration.ConfigElementLink`1.get_Element() +148 Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.TryGetValueInternal(TKey key, TElement& element) +88 Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.get_Item(TKey key) +53 Telerik.Sitefinity.Web.UI.ContentUI.ContentViewControlDefinition.GetConfigurationDefinition() +84 Telerik.Sitefinity.Web.UI.DefinitionBase.get_ConfigDefinition() +48 Telerik.Sitefinity.Web.UI.DefinitionBase.ResolveProperty(String propertyName, T instanceValue, T defaultValue) +376 Telerik.Sitefinity.Web.UI.DefinitionBase.ResolveProperty(String propertyName, T instanceValue) +109 Telerik.Sitefinity.Web.UI.ContentUI.ContentViewControlDefinition.get_ManagerType() +61 Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveContentManager() +52 Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveDetailItem() +128 Telerik.Sitefinity.Web.UI.ContentUI.ContentView.CreateChildControls() +83 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272Hi,
The error message indicates ContentViewDefinitionElement can`t instantiated because this class ContentViewDefinitionElement is abstract class. When using it must call for non abstract class in order to work. This is a sample of how ContentViewDefinitionElement is used in Sitefinity source code.
private static ContentViewDefinitionElement DefineProductAttributeBackendInsertView(ContentViewControlElement backendContentView) var productAttributeInsertView = new DetailFormViewElement(backendContentView.ViewsConfig) Title = "CreateAProductAttribute", ViewName = ProductAttributeDefinitions.ProductAttributesBackendInsertViewName, ViewType = typeof(DetailFormView), ShowSections = true, DisplayMode = FieldDisplayMode.Write, ShowTopToolbar = true, ResourceClassId = typeof(CatalogResources).Name, WebServiceBaseUrl = CatalogModule.productAttributesServiceUrl, IsToRenderTranslationView = true, UseWorkflow = false ; ProductAttributeDefinitions.CreateBackendSections(productAttributeInsertView, FieldDisplayMode.Write); DefinitionsHelper.CreateBackendFormToolbar(productAttributeInsertView, typeof(CatalogResources).Name, true, "ThisProductAttribute", false, false, "BackToProductAttributes", false); return productAttributeInsertView; Ok, I did a comparison and the main difference I found was that I was missing the "public" declaration for the class. I since recompiled and re registered the module with a fresh sitefinity project and it didn't install. I have since found out about the error.log file in App_Data\Sitefinity\Logs and noticed the following error:
Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Message : An item with the same key has already been added.Source : mscorlibHelp link : ParamName : Data : System.Collections.ListDictionaryInternalTargetSite : Void ThrowArgumentException(System.ExceptionResource)Stack Trace : at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.Add(TKey key, TElement element) at Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.Add(TElement element) at Jobs.Resources.JobsDefinitions.DefineJobsBackendContentView(ConfigElement parent) in C:\working\Sitefinity 5.0\Projects\Jobs\Resources\JobsDefinitions.cs:line 84 at Jobs.Configuration.JobsConfig.InitializeDefaultViews(ConfigElementDictionary`2 contentViewControls) in C:\working\Sitefinity 5.0\Projects\Jobs\Configuration\JobsConfig.cs:line 26 at Telerik.Sitefinity.Modules.GenericContent.Configuration.ContentModuleConfigBase.OnPropertiesInitialized() at Telerik.Sitefinity.Configuration.ConfigSection.InitializeProperties() at Telerik.Sitefinity.Configuration.ConfigElement.EnsurePropertiesInitialized() at Telerik.Sitefinity.Configuration.ConfigElement.get_Properties() at Telerik.Sitefinity.Configuration.ConfigElement.get_Item(String propertyName) at Telerik.Sitefinity.Modules.GenericContent.Configuration.ContentModuleConfigBase.get_ContentViewControls() at Telerik.Sitefinity.Services.ModuleBase.InstallContentViews(SiteInitializer initializer, Version upgradeFrom) at Telerik.Sitefinity.Services.ModuleBase.Install(SiteInitializer initializer, Version upgradeFrom) at Telerik.Sitefinity.Services.SystemManager.InitializeModule(ModuleSettings settings, InstallContext installContext, Boolean start)Hi,
A module with the same name have been registered in the project before. This is the cause of the error "An item with the same key has already been added."
There is no uninstall procedure for a module that will completely remove it from Sitefinity since the module uses mapping to the database and the tables it have created in the database remain.
The module writes it in the configuration files of Sitefinity located in App_Data/Sitefinity/Configuration. Remove the module entry from the configuration files
SystemConfig.config
The registration for the module must appear in this configuration file if it have been registered trough Administration->Settings->Advanced->System
<add title="Jobs" type="Jobs.JobsModule" startupType="OnApplicationStart" name="Jobs" /><customSet setName="Jobs"> <securedObjectCustomPermissionSets> <securedObjectType typeName="Jobs.Model.JobApplication">
...
<add title="Jobs" type="Jobs.JobsModule" startupType="OnApplicationStart" name="Jobs" />type="Jobs.JobsModule" (namespace.class of the JobsModule.cs file where the Install method is located).[assembly: AssemblyVersion("1.0.*")][assembly: AssemblyFileVersion("1.0.0.0")]<add title="Jobs" type="Jobs.JobsModule" startupType="OnApplicationStart" version="1.2.3.56" name="Jobs" />Cannot create an instance of Telerik.Sitefinity.Web.UI.ContentUI.Config.ContentViewDefinitionElement because it is an abstract class.".Hi Stanislav,