When creating custom fields in SharePoint you may encounter the following error:
Object reference not set to an instance of an object. at Microsoft.SharePoint.SPSimpleItem.get_Xml()
at Microsoft.SharePoint.ApplicationPages.FieldNewPage.Save()
at Microsoft.SharePoint.ApplicationPages.FieldNewPage.BtnOk_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
After much investigation it seems that when inheriting from SPField, it’s necessary to override FieldTypeValue since the base implementation of this returns null, which causes problems elsewhere.
Usually you’ll probably want to use something like:
public override Type FieldValueType
{
get
{
return typeof(string);
}
}
For more info on how to create custom fields by inheriting from SPField please see this post.