Did this article resolve your question/issue?



Unable to cast object of type 'System.String' to type 'System.Type' error after upgrade of Sitefinity

« Go Back


TitleUnable to cast object of type 'System.String' to type 'System.Type' error after upgrade of Sitefinity
URL NameUnable-to-cast-object-of-type-System-String-to-type-System-Type-error-after-upgrade
Article Number000125687
EnvironmentProduct: Sitefinity
Version: 9.x, 10.x, 11.x, 12.x, 13.x
OS: All supported OS versions
Database: All supported Microsoft SQL Server versions
Question/Problem Description

When running the project in browser after upgrade Sitefinity displays the below error message:

Unable to cast object of type 'System.String' to type 'System.Type'

unable to cast string

Steps to Reproduce
Clarifying Information
Error MessageUnable to cast object of type 'System.String' to type 'System.Type'
Defect Number
Enhancement Number
The issue is caused by missing assemblies in the project's bin folder, or incorrect references, or incorrect configurations.
Copy the assemblies (the .dll files) from the _EmptyProject (which is the same version as your current upgraded Sitefinity version) and paste them to the Sitefinity project's bin folder. Make sure to reference the assemblies from the project's bin folder.

If using NuGet packages, ensure the project is upgraded following the steps from: Sitefinity Documentation, Upgrade a project that uses NuGet packages

The issue can also be caused by incorrect configurations pointing to types that cannot be resolved:
[InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Type'.]
   Telerik.Sitefinity.Configuration.ConfigElement.GetValueFromString(String stringValue, ConfigProperty property) +89
   Telerik.Sitefinity.Configuration.ConfigElementDictionary`2.GetElementByKey(String key) +84
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadCollectionElement(ConfigElementCollection collection, XmlReader reader, LoadContext loadContext, Boolean& skipNextRead, ConfigElement& element) +1460
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, LoadContext loadContext, Boolean isNew, Boolean validateTagName) +1056
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadPropertyElement(ConfigElement element, XmlReader reader, LoadContext loadContext) +448
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadElement(ConfigElement element, XmlReader reader, LoadContext loadContext, Boolean isNew, Boolean validateTagName) +1211
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSectionFromReader(ConfigSection section, XmlReader reader, LoadContext loadContext) +275
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSectionFromFile(ConfigSection section, LoadContext loadContext) +141
   Telerik.Sitefinity.Configuration.Data.XmlConfigProvider.LoadSection(ConfigSection section) +82
   Telerik.Sitefinity.Configuration.ConfigSection.Initialize(ConfigProvider provider) +154
   Telerik.Sitefinity.Configuration.Config.GetSectionInternal(Type sectionType, Boolean safeMode, String sectionName) +179
   Telerik.Sitefinity.Configuration.Config.GetSectionPrivate(Type sectionType, Boolean safeMode, String sectionName) +192
   Telerik.Sitefinity.Configuration.Config.GetSectionPrivate(Boolean safeMode) +99
   Telerik.Sitefinity.Web.UI.ControlUtilities..cctor() +35

[TypeInitializationException: The type initializer for 'Telerik.Sitefinity.Web.UI.ControlUtilities' threw an exception.]
   Telerik.Sitefinity.Abstractions.VirtualPath.Configuration.VirtualPathSettingsConfig.OnPropertiesInitialized() +60
   Telerik.Sitefinity.Configuration.ConfigSection.InitializeProperties() +25
   Telerik.Sitefinity.Configuration.ConfigElement.EnsurePropertiesInitialized() +123

A possible cause is an incorrect assembly reference in the SystemConfig.config. For example, for the Site Sync module under the <typeImplementationsMapping> collection:
<add type="Telerik.Sitefinity.SiteSync.Web.UI.Fields.SyncDetailsListFieldDefinitionElement, Telerik.Sitefinity.SiteSync" />
<add type="Telerik.Sitefinity.SiteSync.Web.UI.Fields.SyncSummaryFieldDefinitionElement, Telerik.Sitefinity.SiteSync" />

instead of:

<add type="Telerik.Sitefinity.SiteSync.Web.UI.Fields.SyncDetailsListFieldDefinitionElement, Telerik.Sitefinity.SiteSync.Impl" />
<add type="Telerik.Sitefinity.SiteSync.Web.UI.Fields.SyncSummaryFieldDefinitionElement, Telerik.Sitefinity.SiteSync.Impl" />

Search the configurations for any custom types. For example, a record pointing to a type that no longer exists in the project in ControlsConfig:
<?xml version="1.0" encoding="utf-8"?>
<controlsConfig xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="10.0.6400.0">

<viewSettings layoutTemplatePath="~/Custom/ExternalTemplates/MyLoginWidget.ascx" hostType="SitefinityWebApp.MyLoginForm, SitefinityWebApp" />

References to Other Documentation:
Sitefinity Documentation, Upgrade procedure
Last Modified Date6/30/2021 2:01 PM
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.