Moved from http://blogs.msdn.com/vijgang

Worked on an interesting case the other day. The customer had a variation enabled SharePoint site with multiple sites for different languages. He would export one of the language based site and sends it to the company that handles the translation. Once the export file (.cmp) was converted and returned, he used to import it back into the variation site for that specific language. This used to work for all languages, but failed for one specific site.

The import would fail with the following error: (You will see this error if debug & callstack are set to true in the web.config).

<error><message>An error occurred while parsing EntityName. Line 4, position 38.</message><full>System.Xml.XmlException: An error occurred while parsing EntityName. Line 4, position 38. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, Int32 lineNo, Int32 linePos) at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&amp; charRefEndPos) at System.Xml.XmlTextReaderImpl.ParseText(Int32&amp; startPos, Int32&amp; endPos, Int32&amp; outOrChars) at System.Xml.XmlTextReaderImpl.FinishPartialValue() at System.Xml.XmlTextReaderImpl.get_Value() at System.Xml.XmlReader.ReadString() at System.Xml.XmlTextReaderImpl.ReadString() at Microsoft.SharePoint.Publishing.SummaryLink..ctor(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.SummaryLinkCollection.Deserialize(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue.deserializeSummaryLinks(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue.deserialize(String serializedValue) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue..ctor(String serializedValue) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkField.GetFieldValue(String value) at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, SPField field, Boolean protectFields) at Microsoft.SharePoint.SPListItem.set_Item(Guid fieldId, Object value) at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, ImportObjectManager objectManager, Guid docId, String fieldName, String value, String value2, Guid gFieldId, Boolean&amp; bCreated, Dictionary`2 brokenFields) at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, Guid docId, Boolean&amp; bCreated, SPContentTypeId contentTypeId, ImportObjectManager objectManager, Object data) at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject) at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader) at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects() at Microsoft.SharePoint.Deployment.SPImport.Run() at Microsoft.SharePoint.Publishing.Internal.DeploymentWrapper.ImportObjects(String fileName) at Microsoft.SharePoint.Publishing.Internal.WebControls.ImportVariation.DoWork() at Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob.&lt;ThreadEntryPoint&gt;b__11() at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock)</full><customData></customData></error><error><message>An error occurred while parsing EntityName. Line 4, position 38.</message><full>System.Xml.XmlException: An error occurred while parsing EntityName. Line 4, position 38. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, Int32 lineNo, Int32 linePos) at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&amp; charRefEndPos) at System.Xml.XmlTextReaderImpl.ParseText(Int32&amp; startPos, Int32&amp; endPos, Int32&amp; outOrChars) at System.Xml.XmlTextReaderImpl.FinishPartialValue() at System.Xml.XmlTextReaderImpl.get_Value() at System.Xml.XmlReader.ReadString() at System.Xml.XmlTextReaderImpl.ReadString() at Microsoft.SharePoint.Publishing.SummaryLink..ctor(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.SummaryLinkCollection.Deserialize(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue.deserializeSummaryLinks(XmlReader reader, Int32 deserializedSchemaVersion) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue.deserialize(String serializedValue) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue..ctor(String serializedValue) at Microsoft.SharePoint.Publishing.Fields.SummaryLinkField.GetFieldValue(String value) at Microsoft.SharePoint.SPListItem.SetValue(String strName, Object value, SPField field, Boolean protectFields) at Microsoft.SharePoint.SPListItem.set_Item(Guid fieldId, Object value) at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, ImportObjectManager objectManager, Guid docId, String fieldName, String value, String value2, Guid gFieldId, Boolean&amp; bCreated, Dictionary`2 brokenFields) at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, Guid docId, Boolean&amp; bCreated, SPContentTypeId contentTypeId, ImportObjectManager objectManager, Object data) at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject) at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader) at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects() at Microsoft.SharePoint.Deployment.SPImport.Run() at Microsoft.SharePoint.Publishing.Internal.DeploymentWrapper.ImportObjects(String fileName) at Microsoft.SharePoint.Publishing.Internal.WebControls.ImportVariation.DoWork() at Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob.&lt;ThreadEntryPoint&gt;b__11() at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock) at Microsoft.Office.Server.Diagnostics.ULS.SendWatsonOnExceptionTag(ULSTagID tagID, ULSCat categoryID, String output, Boolean fRethrowException, TryBlock tryBlock, CatchBlock catchBlock, FinallyBlock finallyBlock) at Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob.&lt;ThreadEntryPoint&gt;b__f() at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock)</full><customData></customData></error>

The ULS Logs would throw an error - "An error occurred while parsing EntityName. Line 4, position 38." followed by the callstack.

 

So this surely looks like a malformed XML file. So we extracted the Manifest.XML file and opened it up in Internet Explorer, expecting it to fail with a similar error - no luck here! After some research and some code to parse the XML file, we got closer to the problem. This was happening because the manifest.xml file had tags that have values which were treated as STRINGs and they internally were again encoded XML strings. So when the import job runs, it extracts the value from the parent XML and then decodes the value to form a new XML string which is again parsed. This is where the failure used to happen. We had a huge Manifest.xml file, so to speed up the process,

So we attached a debugger to the import job and when the exception happened, dumped the stack and found the string that caused the issue.

The exported version of the manifest.xml had the following XML string :

<Field Name="SummaryLinks2" Value="&lt;div title=&quot;_schemaversion&quot; id=&quot;_3&quot;&gt;&#xD;&#xA; &lt;div title=&quot;_links&quot;&gt;&#xD;&#xA; &lt;div title=&quot;_link&quot;&gt;&#xD;&#xA; &lt;span title=&quot;_title&quot;&gt;Hot &amp;amp; Cold&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_order&quot;&gt;1&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_begincolumn&quot;&gt;True&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_description&quot;&gt;Description&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_linkurl&quot;&gt;&#xD;&#xA; &lt;a href=&quot;/English/Documents/Forms/AllItems.aspx&quot;&gt;/English/Documents/Forms/AllItems.aspx&lt;/a&gt;&#xD;&#xA; &lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_style&quot;&gt;Default&lt;/span&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA; &lt;div title=&quot;_view&quot;&gt;&#xD;&#xA; &lt;span title=&quot;_columns&quot;&gt;1&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_linkstyle&quot;&gt;&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_groupstyle&quot;&gt;&lt;/span&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA;&lt;/div&gt;" FieldId="27761311-936a-40ba-80cd-ca5e7a540a36" />

</Fields>

The imported version had the following XML:

<Field Name="SummaryLinks2" Value="&lt;div title=&quot;_schemaversion&quot; id=&quot;_3&quot;&gt;&#xD;&#xA; &lt;div title=&quot;_links&quot;&gt;&#xD;&#xA; &lt;div title=&quot;_link&quot;&gt;&#xD;&#xA; &lt;span title=&quot;_title&quot;&gt;Hot &amp; Cold&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_order&quot;&gt;1&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_begincolumn&quot;&gt;True&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_description&quot;&gt;Description&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_linkurl&quot;&gt;&#xD;&#xA; &lt;a href=&quot;/English/Documents/Forms/AllItems.aspx&quot;&gt;/English/Documents/Forms/AllItems.aspx&lt;/a&gt;&#xD;&#xA; &lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_style&quot;&gt;Default&lt;/span&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA; &lt;div title=&quot;_view&quot;&gt;&#xD;&#xA; &lt;span title=&quot;_columns&quot;&gt;1&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_linkstyle&quot;&gt;&lt;/span&gt;&#xD;&#xA; &lt;span title=&quot;_groupstyle&quot;&gt;&lt;/span&gt;&#xD;&#xA; &lt;/div&gt;&#xD;&#xA;&lt;/div&gt;" FieldId="27761311-936a-40ba-80cd-ca5e7a540a36" />

</Fields>

So what really happens is if you have a Summary Links Web Part on the variation page and it has text like "Hot&Cold", then this would be encoded the first time as Hot&amp;Cold. Now when this is packaged in the Manifest.xml - this is again encoded to form Hot&amp;amp;Cold and this structure needs to be mainted. The XML encoded values should not be changed. You will find more information on this at http://support.microsoft.com/kb/251354