4

我最近将一个 Sharepoint 2010 站点迁移到 Sharepoint 2013,从那时起,我在 Visual Studio 中开发的自定义工作流完美运行了 2 年,在迁移后它突然开始抛出此异常,没有出现故障。

w3wp.exe (0x4D3C)                           0x10F0  SharePoint Foundation           Legacy Workflow Infrastructure  88xr    Unexpected
WinWF Internal Error, terminating workflow Id# 21492445-9c27-479c-ae16-5d0d3ae84b69 

w3wp.exe (0x4D3C)                           0x10F0  SharePoint Foundation           Legacy Workflow Infrastructure  98d4    Unexpected
Microsoft.SharePoint.SPException: Cannot complete this action.  Please try again. ---> System.Runtime.InteropServices.COMException: Cannot complete this action.  
Please try again.<nativehr>0x80004005</nativehr><nativestack></nativestack>     
at Microsoft.SharePoint.Library.SPRequestInternalClass.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.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)     
--- End of inner exception stack trace ---     
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 ProductList.AutoApprovalProcess.ApprovalWorkflow.AuthorizeItem()     
at ProductList.AutoApprovalProcess.ApprovalWorkflow.onWorkflowActivated1_Invoked(Object sender, ExternalDataEventArgs e)     
at System.Workflow.ComponentModel.Activity.RaiseGenericEvent[T](DependencyProperty dependencyEvent, Object sender, T e)     
at System.Workflow.Activities.HandleExternalEventActivity.RaiseEvent(Object[] args)     
at System.Workflow.Activities.HandleExternalEventActivity.Execute(ActivityExecutionContext executionContext)     
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)     
at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)     
at System.Workflow.Runtime.Scheduler.Run()

我查看了我的代码,看看 ApprovalWorkflow.AuthorizeItem() 上到底发生了什么然后它没什么特别的,这就是它的作用

private void AuthorizeItem()
{
    workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Approved;
    workflowProperties.Item.Update();
}

基本上,工作流程只是根据项目满足的特定条件自动批准项目。然后我在工作流信息中看到的是这个

在此处输入图像描述

它由 ActivityExceutionStatus 抛出

protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext, Exception exception)
{
    ((ISharePointService)executionContext.GetService(typeof(ISharePointService))).LogToHistoryList(base.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.MinValue, string.Empty, string.Format("WorkFlow Exception!: {0}", exception.Message), string.Empty);
    return ActivityExecutionStatus.Closed;
}

请注意,并非每次调用工作流时都会发生这种情况,有时会发生我不知道触发什么的情况

有谁知道是什么原因导致这种情况以及如何防止它再次发生?

为清楚起见,下面添加了更新 1 实际代码

public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
pblic enum ThresholdItem { MultipleThreshold, NoThreshold, BelowThreshold, AboveThreshold, Valid };

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
    switch (ThresholdCheck())
    {
        case ThresholdItem.Valid:
            AuthorizeItem();
            break;
        case ThresholdItem.BelowThreshold:
            RequestDenied("Below Threshold");
            break;
        case ThresholdItem.AboveThreshold:
            RequestDenied("Above Threshold");
            break;
        case ThresholdItem.NoThreshold:
            RequestDenied("No Threshold Defined");
            break;
        case ThresholdItem.MultipleThreshold:
            RequestDenied("Multiple Threshold Defined");
            break;
    }
}   


private ThresholdItem ThresholdCheck()
{
    SPLinqDataContext dc = new SPLinqDataContext(workflowProperties.SiteUrl + "/Testing");

    EntityList<ThresholdsItem> PriceThreshold = dc.GetList<ThresholdsItem>("Thresholds");

    string destination = GetLinkedListItemString(workflowProperties.Item["Destination"].ToString());
    string origin = GetLinkedListItemString(workflowProperties.Item["Origin"].ToString());
    double price = double.Parse(workflowProperties.Item["Price"].ToString());

    var Result = (from p in Threshold
                    where
                        p.Destination.Title == destination &&
                        p.Origin.Title == origin
                    select p);
    switch (Result.Count())
    {
        case 1:
            var SingleResult = Result.SingleOrDefault();
            if (SingleResult.MinPrice > price)
                return ThresholdItem.BelowThreshold;
            else if (SingleResult.MaxPrice < price)
                return ThresholdItem.AboveThreshold;
            else
                return ThresholdItem.Valid;
        case 0:
            return ThresholdItem.NoThreshold;

        default:
            return ThresholdItem.MultipleThreshold;

    }
}

private void RequestDenied(string note)
{
    workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Denied;
    workflowProperties.Item.ModerationInformation.Comment = note;
    workflowProperties.Item.Update();
}

private string GetLinkedListItemString(string item)
{
    if (item.Contains("#"))
    {
        return sItem.Substring(item.LastIndexOf("#") + 1);
    }
    else
    {
        return item;
    }
}
4

1 回答 1

3

好的,我似乎发现了问题,如果您仔细阅读它,它就在代码本身中。希望这个解决方案能在未来对某人有所帮助。

发生的情况是工作流进行多次循环,当用户更新列表项时会发生这种情况,它会触发运行工作流。接下来会发生什么是工作流工作线程审核该项目并将其设置为已批准,这又会再次触发工作流,然后它会一次又一次地运行,直到 SharePoint 决定终止它?(还不确定如何,但我注意到它只运行了 10 次)。我注意到 Sharepoint 2010 处理得非常好,但 Sharepoint 2013 没有,并且偶尔会抛出异常。

如果您查看它之前运行 10 次的图像(红色突出显示的项目),但在修复它之后,我尝试了两次,现在它按预期运行(蓝色和绿色突出显示的项目)。

那么更新过程不会再次触发工作流的修复方法是什么,我通过遵循这个解决方案做到了这一点:https ://stackoverflow.com/a/2468156/412519

然后将我的更新更改为

workflowProperties.Item.Update(true);

在此处输入图像描述

于 2013-11-20T20:29:22.353 回答