使用GetItemById出错“Detected use of SPRequest for previously closed SPWeb object.”
2014-02-14 11:50
381 查看
这个log错误信息又出现了:“Detected use of SPRequest for previously closed SPWeb object.”。这次是在GetItemById这个方法中抛出的,很奇怪为什么这个方法会使用web。查看了一下代码才知道,这个方法确实用到了list的web属性。
GetItemById方法在获取item的步骤是
1.使用Query查询,通过传入的item的id,查询list中的item,得到一个SPListItemCollection集合,这个集合的名字是items。这里没有任何问题。
2.判断这个集合是不是空的集合,方法是使用items.Count属性,如果不是空的集合,就返回Items[0]这个item。问题出在items.Count这个属性,这个属性调用了SPListItemCollection的EnsureListItemsData()方法,这个方法中使用了list的Web,因此报出了下面的完整的错误信息:
所以这个时候,需要检查list的web是否已经被释放了。
如何正确避免这样的错误请参见:点击打开链接
GetItemById方法在获取item的步骤是
1.使用Query查询,通过传入的item的id,查询list中的item,得到一个SPListItemCollection集合,这个集合的名字是items。这里没有任何问题。
2.判断这个集合是不是空的集合,方法是使用items.Count属性,如果不是空的集合,就返回Items[0]这个item。问题出在items.Count这个属性,这个属性调用了SPListItemCollection的EnsureListItemsData()方法,这个方法中使用了list的Web,因此报出了下面的完整的错误信息:
Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before. Stack trace: at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() at Microsoft.SharePoint.SPListItemCollection.get_Count() at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean bDatesInUtc) at Microsoft.SharePoint.SPList.GetItemById(Int32 id) at...
所以这个时候,需要检查list的web是否已经被释放了。
如何正确避免这样的错误请参见:点击打开链接
相关文章推荐
- SharePoint log分析——“Detected use of SPRequest for previously closed SPWeb object. ”
- Use GetObjectByKey() for better performance
- Is there a complete list of PSPROJECTITEM.OBJECTTYPE Values for PeopleTools 8.51?
- Enhancement of SSD by concatenating feature maps for object detection笔记
- 【ask】Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
- 使用json_decode()转换返回数组或对象时出现:Cannot use object of type stdClass as array
- Item 1: 尽可能的使用属性代替可访问的数据成员(Always Use Properties Instead of Accessible Data Members)
- 在使用visual studio 2013写程序时 ,出现了(“The POSIX name for this item is deprecated. Instead, use the ISO C+
- 使用Idhttp.get('') 造成假死(堵塞),请问线程idhttp怎么才能做到不出错?
- Trying to use an SPWeb object that has been closed or disposed and is no longer valid.
- org.springframework.data.mapping.model.MappingException: No id property found for object of type
- C# 使用 GetOleDbSchemaTable 检索架构信息(表、列、主键等)--链接http://hi.baidu.com/useforprograms/blog/item/b2627decd024074778f05587.html
- [论文笔记]Enhancement of SSD by concatenating feature maps for object detection
- 卫星图像分割--Effective Use of Dilated Convolutions for Segmenting Small Object Instances
- SharePoint 2010中新增的GetItemByIdSelectedFields方法
- Trying to use an SPWeb object that has been closed or disposed and is no longer valid.
- 卫星图像分割--Effective Use of Dilated Convolutions for Segmenting Small Object Instances
- Examples of how to use Error Logging for SQL statements (Doc ID 1076042.1)
- 'NoneType' object has no attribute '__getitem__'和argument of type 'NoneType' is not iterable 异常的解决办法
- Effective JavaScript Item 31 优先使用Object.getPrototypeOf,而不是__proto__