'Length cannot be less than zero' error in SPImport

Recently, we came across an issue with SPImport. On attempting an import using Content Deployment APIs, we received the following error.

Length cannot be less than zero.
Parameter name: length

This error occurred during the import of a ListItem. We thought it could be a code issue, but actually it was not. We got the same error when we tried the import operation using stsadm command as well. Then we realised that there is something wrong with the data/properties.

We did further analysis and found out that it was a custom site column in our content type which causes this issue. The custom column is of type 'SPUser'. We deploy this custom column through a field definition file. The error occurs because the field was missing an attribute called List="UserInfo" in its definition. SPImport operation was successfully executed after adding this attribute to the column.

Whenever you add a custom field of type SPUser, please ensure that the attribute List="UserInfo" is added to the field definition.

2 comments:

Anonymous said...

Great Post. We are having a very similar problem, but don't see it being a custom column.. though somehow possibly related to column types.

In our case we are trying to migrate (via export/import) from a subsite to a new site collection on a new Farm.

The subsite is template type IT.

while importing the bugs list, we get this and the import just stops.

[3/5/2009 6:12:55 PM]: FatalError: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at Microsoft.SharePoint.Deployment.ListItemSerializer.GetLookupInfoFromFieldData(Object value, Guid& lookupListId, Int32& lookupItemId, Boolean& isUserLookup, String& userLogin, String& mvlVal)
at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, ImportObjectManager objectManager, Guid docId, String fieldName, String value, String value2, Guid gFieldId, Boolean& bCreated, Dictionary`2 brokenFields)
at Microsoft.SharePoint.Deployment.ListItemSerializer.UpdateFieldData(SPListItem listItem, Guid docId, Boolean& bCreated, SPContentTypeId contentTypeId, ImportObjectManager objectManager, Object data)
at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()
[3/5/2009 6:12:56 PM]: Progress: Import Completed.


If you could email me at jc_pineiro(at)yahoo(dot)com.

Thank you!

Reggie said...

Hi,

I tried to create a new user column using the interface to see if I would get the same error.

I didn't get the error however it doesn't save the value of the user field and any version history that deals with that field is blank.

I was wondering if you noticed this