我正在尝试将我的 sharepoint 项目分解为几个较小的项目。我可以轻松地在不同的项目中移动实用程序文件。但是,当我移动自定义字段时遇到了问题。
如果我将自定义字段从 ProjectA 移动到 ProjectB 并将 ProjectA 设置为引用 ProjectB 的 DLL,则构建和部署工作正常。但是,当程序从 SPListItem 引用自定义字段时,它会抛出 System.ArgumentOutOfRangeException。
例如
SPListItem item = splist.GetItemById(id);<br>
CustomFieldValue custom = item["Custom"] // Error occurs here
另外,如果我调用 AddFieldAsXml 来定义上面的自定义字段,我会得到同样的错误。
谁能帮我解决这个问题?先感谢您...
AddFieldAsXml 中发生的错误的详细信息(引用时发生相同的错误)
Length cannot be less than zero.
Parameter name: length
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7494967
System.String.Substring(Int32 startIndex, Int32 length) +11
Microsoft.SharePoint.Publishing.PublishingHttpModule.CreateSPField(String fieldTypeName, SPFieldCollection collection, String fieldName) +80
Microsoft.SharePoint.SPFieldCollection.CreateSPField(Int32 index) +2746
Microsoft.SharePoint.SPFieldCollection.EnsureSPField(Int32 index) +89
Microsoft.SharePoint.SPFieldCollection.get_Item(Int32 iIndex) +113
Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName, Boolean bThrowException) +180
Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName) +38
Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) +905
Microsoft.SharePoint.SPFieldCollection.AddFieldAsXml(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) +45
如果 string.substring(int startIndex, int length) 的长度值为负数,则会显示此错误...但我不知道为什么会出现此错误。