2

这个很奇怪。

我正在 SharePoint 2010 的计时器作业中执行此代码...

...
// Get the field by it's internal name
SPField field = item.Fields.GetFieldByInternalName(fieldInternalName);

if (field != null)
{
     SPFieldUser userField = (SPFieldUser)field;
     object value = null;

     if (userField.AllowMultipleValues)
     {
          // Bug when getting field value in a timer job? Throws an ArgumentException
          users = new SPFieldUserValueCollection(item.ParentList.ParentWeb, item[userField.Id].ToString());
     }
     else
     {
          // Get the value from the field, no exception
          value = item[userField.Id];
     }
}
...

此代码在简单的 ConsoleApplication 中运行时运行良好,但在 SharePoint 2010 中的计时器作业上下文中运行时,它会在行中引发 ArgumentException ...

users = new SPFieldUserValueCollection(item.ParentList.ParentWeb, item[userField.Id].ToString());

我尝试了许多变体来从 SPFieldUser 检索值,但只有在 Timer Job 正在执行它并且该字段的 AllowMultipleValues 属性设置为 TRUE 时才会失败。

我已经尝试使用 Reflector 进行调试,并且似乎在 SPListItem 中抛出了异常......

public object this[Guid fieldId]
{
  get
  {
    SPField fld = this.Fields[fieldId];
    if (fld == null)
    {
      throw new ArgumentException();
    }
    return this.GetValue(fld, -1, false);
}
...

这将是异常堆栈跟踪...

System.ArgumentException was caught
Message=Value does not fall within the expected range.
Source=Microsoft.SharePoint
StackTrace:
     at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow)
     at Microsoft.SharePoint.SPListItemCollection.GetColumnNumber(String groupName, Boolean bThrowException)
     at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, Int32 iIndex, Boolean bThrow)
     at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw, Boolean bThrowException)
     at Microsoft.SharePoint.SPListItem.get_Item(Guid fieldId)
     at FOCAL.Point.Applications.Audits.AuditUtility.GetPeopleFromField(SPListItem item, String fieldInternalName)

唉……有什么想法吗?

4

1 回答 1

1

这通常意味着您在单个 SPQuery 中请求了过多的查找字段,这将导致内容数据库中的真实查找表的自联接过多,除非 SharePoint Foundation 限制了资源。对于普通用户,有一个阈值设置为每次查询 8 次查找。确保您的查询仅返回必要的查找或人员/组字段。如果您无法减少使用量,请考虑更改阈值设置。

于 2011-11-24T12:01:44.210 回答