Error when rebuilding the Core Link Database


Description

The Attempted to load invalid xml error might occur when rebuilding the Link database for the Core database. The issue happens if the Final Renderings field of EXM items contains the colon symbol (:). The log file might contain the following exception:

ManagedPoolThread #0 2018:03:07 09:37:00 
ERROR Attempted to load invalid xml.
Exception: System.Xml.XmlException
Message: Data at the root level is invalid. Line 1, position 1.
Source: System.Xml
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at Sitecore.Xml.XmlUtil.LoadXml(String xml)
ManagedPoolThread #0 2018:03:07 09:37:00 ERROR First 200 characters: :
ManagedPoolThread #0 2018:03:07 09:37:00 ERROR Call stack: at Sitecore.MainUtil.GetCallStack()
   at Sitecore.Xml.XmlUtil.LoadXml(String xml)
   at Sitecore.Data.Fields.LayoutField..ctor(Field innerField)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sitecore.Reflection.ReflectionUtil.CreateObject(Type type, Object[] parameters)
   at Sitecore.Data.Fields.FieldType.GetField(Field field)
   at Sitecore.Data.Fields.DefaultFieldTypeManager.GetField(Field field, String runtimeValue)
   at Sitecore.Links.ItemLinks.AddLinks(Field field, List`1 links, ItemLinkState linkState)
   at Sitecore.Links.ItemLinks.GetLinks(ItemLinkState linkState, Boolean allVersions, Boolean includeStandardValuesLinks)
   ...

Solution

To resolve the issue, do the following:
  1. Back up the Core database.
  2. Run the following SQL script in order to examine which items contain the affected Final Renderings field:
    SELECT * FROM [coreDbName].[dbo].[VersionedFields] where [FieldId]='{04BF00DB-F5FB-41F7-8AB7-22408372A981}' and [Value]=':'
  3. Run the following script to delete the Final Renderings fields:
    DELETE FROM [coreDbName].[dbo].[VersionedFields] where [FieldId]='{04BF00DB-F5FB-41F7-8AB7-22408372A981}' and [Value]=':'
  4. Restart the Sitecore XP instance.