如何知道哪一段代码是异常的原因?

时间:2014-09-17 05:12:36

标签: c# sharepoint-2013

如何知道哪一段代码可能导致异常' SPException未处理'?

CODE:

SPList mylist = web.Lists.TryGetList("mylist"); 
SPListItem item = mylist.Items.Add(); 
... ... ... 

item.Update();

跟踪是:

Stack details:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)     
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bUnRestrictedUpdateInProgress, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback)
       at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents, String filename, Boolean bPreserveItemUIVersion)
       at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents, String filename, Boolean bPreserveItemUIVersion)
       at Microsoft.SharePoint.SPListItem.Update()
       at Dumper.Program.Main(String[] args) in c:\users\svcspfarm\documents\visual studio 2010\Projects\Dumper\Dumper\Program.cs:line 364
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

2 个答案:

答案 0 :(得分:0)

查看sharepoint ULS日志以查找有关异常的更多信息。

\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

对我而言,您似乎没有为所需列表字段设置值。

答案 1 :(得分:0)

从堆栈跟踪中查看这些行:

  at Microsoft.SharePoint.SPListItem.Update()
  at Dumper.Program.Main(String[] args) in c:\users\svcspfarm\documents\visual studio 2010\Projects\Dumper\Dumper\Program.cs:line 364

调用item.Update();时发生异常。当我尝试将一个子文件夹添加到列表中时,我遇到了类似的问题,导致问题的原因可能并不明显。我会猜到,在您致电mylist.Items.Add();Update()之间某处未正确设置某些内容。新的列表项可能包含一些需要在更新之前初始化的必填字段吗?