Archive

Archive for August, 2014

SharePoint 2013 – COMException 0x8007047e When Adding A Field To A List By An Event Receiver

2014/08/27 1 comment

I was trying to add a computed field to a list when ever another field (in this case a Taxonomy field) was added. This was to support custom rendering options for the taxonomy fields values since you can’t modify the JSLink options directly on a taxonomy field. Everything worked the first time, but in hardening the code I started receiving the error:

System.Runtime.InteropServices.COMException: 0x8007047e, StackTrace: at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op, Boolean isMigration, Boolean fResetCTCol) at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXml(String strXml)

Unfortunately there was no actual error message, just the error code, but it turns out that this is generally a save conflict error in SharePoint.

So it had worked a few times then started throwing the error, and at first I was adding the second field during the FieldAdding event, but moved it to the FieldAdded event to try to avoid any conflicts in the first place, but as you can see I still got the error so something else was happening.

Well since I was debugging I was actually providing the conditions for the error, as the taxonomy field also adds its own secondary fields and debugging slowed down the process enough to have both saves occur at the same time, and mine was generally losing out.

So in the end I set the FieldAdded/FieldDeleted event receivers to be Synchronous (via the Elements file but you could do it in code) and now my field and the taxonomy fields secondary field are added without stepping on each other regardless of debugging or not.

Advertisements