Search code examples
c#.netsharepoint-2007

"Operation is not valid due to the current state of the object." when I attempt to unseal a field on a list


I have a few fields on a list that was created using a schema. The schema and list seem to have gotten out of sync, so when I try to change attributes for a field on the schema, those changes are not reflected on the list, unless they are additions (ie, new fields).

I have a few Sealed fields that I need to unseal. But when I attempt to set Sealed=false, either using SharePoint Manager, or using a utility I wrote, I get the error: "Operation is not valid due to the current state of the object." I can't seem to find any more usable information about the error.

On my utility, this happens on the line:

field.Sealed = false;

I haven't even gotten to the point of trying to update the field before an exception is thrown. field.SchemaXml looks fine too. I don't see anything wrong with it.

This is happening on multiple fields in this list.

Anyone know what to do?


Solution

  • What is the error and what is the field that is failing?

    According to MSDN, you cannot change out of the box or external data fields:

    • InvalidOperationException: An attempt is made to assign a value to a field type that is built into SharePoint. The true/false value of such fields must remain at its factory setting.
    • NotSupportedException: An attempt is made to assign false when the SharePoint field is an external data column.

    Update (to highlight information that might be hidden in the comments):

    Call SPBuiltInFieldId.Contains to avoid (or detect) InvalidOperationException. The Sealed property cannot be set if SPBuiltInFieldId.Contains returns true.