Writing tons of xml in order to create SharePoint 2007 site columns and getting and error “The given key was not present in the dictionary.” after deployment isn’t the thing I want to get at the end of the day. After doing some review I found the error which can easily be missed.
Problem description
This is the error I got after deployment which isn’t really helpful:
This is the text:
The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.SharePoint.SPFieldCollection.CreateSPField(Int32 index)
at Microsoft.SharePoint.SPFieldCollection.EnsureSPField(Int32 index)
at Microsoft.SharePoint.SPFieldCollection.get_Item(Int32 iIndex)
at Microsoft.SharePoint.SPFieldCollection.ItemAtIndex(Int32 iIndex)
at Microsoft.SharePoint.SPBaseCollection.SPEnumerator.System.Collections.IEnumerator.get_Current()
at Microsoft.SharePoint.ApplicationPages.FieldListRenderer.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Solution
After deleting every field step by step I found that the following field was creating the error:
<Field ID="{CA57B137-76C9-47e1-A49C-BEA5D819081B}" Name="NAME1"
Type="Url" DisplayName="DISPLAYNAME" Group="GROUP"
AllowDeletion="False" Sealed="TRUE" Format="Hyperlink" />
After reviewing that the type=”Url” is case sensitive and needs to be all uppercase type=”URL”:
<Field ID="{CA57B137-76C9-47e1-A49C-BEA5D819081B}" Name="NAME2"
Type="URL" DisplayName="DISPLAYNAME" Group="GROUP"
AllowDeletion="False" Sealed="TRUE" Format="Hyperlink" />
Just a little mistake which can take a lot of time to find… I hope it saves time for someone else.