“Failed to compare two elements in the array” Error During SPExport.Run

October 08, 2009

I’ve made a custom SPExport and SPImport tool that duplicates site content around the SharePoint site collection. However, it would suddenly run with no visible effects (no content was copied). After digging around the ULS logs (using the excellent log library provided by Ayman el-Hattab) I found out that SharePoint SPExport.Run() method was throwing a strange exception:

> **Failed to compare two elements in the array.** at System.Collections.Generic.ArraySortHelper\`1.QuickSort\[TValue\](T\[\] keys, TValue\[\] values, Int32 left, Int32 right, IComparer\`1 comparer) at System.Collections.Generic.ArraySortHelper\`1.Sort\[TValue\](T\[\] keys, TValue\[\] values, Int32 index, Int32 length, IComparer\`1 comparer) at System.Collections.Generic.ArraySortHelper\`1.Sort(T\[\] items, Int32 index, Int32 length, IComparer\`1 comparer) at System.Array.Sort\[T\](T\[\] array, Int32 index, Int32 length, IComparer\`1 comparer) at System.Collections.Generic.List\`1.Sort(Int32 index, Int32 count, IComparer\`1 comparer) at System.Collections.Generic.List\`1.Sort(IComparer\`1 comparer) at Microsoft.SharePoint.Deployment.WebSerializer.GetDataFromObjectModel(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.DeploymentSerializationSurrogate.GetObjectData(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.XmlFormatter.SerializeObject(Object obj, ISerializationSurrogate surrogate, String elementName, Boolean bNeedEnvelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Serialize(Stream serializationStream, Object topLevelObject) at Microsoft.SharePoint.Deployment.ObjectSerializer.Serialize(DeploymentObject deployObject, Stream serializationStream) at Microsoft.SharePoint.Deployment.SPExport.SerializeObjects() at Microsoft.SharePoint.Deployment.SPExport.Run() \*\*\* **Inner exception: Failed to find the XML file at location '12TemplateFeaturesMyFeaturefeature.xml'** at Microsoft.SharePoint.SPXmlDocCache.GetGlobalXmlDocumentCore(String pathXml, Boolean bFeature) at Microsoft.SharePoint.SPXmlDocCache.GetGlobalXmlDocument(String pathAllFeaturesRelativeXml) at Microsoft.SharePoint.Administration.SPFeatureDefinition.EnsureGlobalDefinition() at Microsoft.SharePoint.Administration.SPFeatureDefinition.get\_Scope() at Microsoft.SharePoint.Administration.SPFeatureDefinition.ActivationDependencyComparer.System.Collections.Generic.IComparer<Microsoft.SharePoint.Administration.SPFeatureDefinition>.Compare(SPFeatureDefinition featdef1, SPFeatureDefinition featdef2) at Microsoft.SharePoint.Deployment.WebSerializer.ExportFeatureComparer.System.Collections.Generic.IComparer<Microsoft.SharePoint.Deployment.ExportObject>.Compare(ExportObject exportObject1, ExportObject exportObject2) at System.Collections.Generic.ArraySortHelper\`1.QuickSort\[TValue\](T\[\] keys, TValue\[\] values, Int32 left, Int32 right, IComparer\`1 comparer)

As you can see (the bolded text above), the real culprit was an orphaned feature that was present on the source site but it’s physical components were not present on the 12/TEMPLATE/FEATURES folder. After the feature redeployment and reactivation, the export job was ready to go.


Profile picture

Written by Edin Kapić Insatiably curious code-writing tinkerer. Geek father. Aviation enthusiast. Cuisine journeyman. Follow me on Twitter