OutArgument <t> .Set()</t>中的InvalidCastException

时间:2011-12-14 15:20:45

标签: workflow-foundation-4

奇怪的例外,这之前工作正常。

System.InvalidCastException: Cannot convert object 'Waiting' to type 'System.Activities.Statements.Pick+PickState'.
   at System.Runtime.TypeHelper.Convert[T](Object source)
   at System.Activities.Location`1.set_ValueCore(Object value)
   at System.Activities.ActivityContext.SetValueCore[T](LocationReference locationReference, T value)
   at System.Activities.ActivityContext.SetValue[T](OutArgument`1 argument, T value)
   at System.Activities.OutArgument`1.Set(ActivityContext context, T value)
   at MyApplication.WaitForStatusChange.OnBookmarkResumed(NativeActivityContext context, Bookmark bookmark, Object value)
   at System.Activities.Runtime.BookmarkCallbackWrapper.Invoke(NativeActivityContext context, Bookmark bookmark, Object value)
   at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

MyApplication.WaitForStatusChange是一个自定义的NativeActivity,当在此活动的书签上恢复工作流时会发生错误,其中包含bookmar参数的枚举。

WaitForStatusChange活动放在Pick活动中(另一个分支上有另一个NativeActivity)

screeshot

活动代码

  public class WaitForPartnerIntegrationStatusChange : NativeActivity
  {
    public OutArgument<PartnerSoftwareIntegrationStatus> Status { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
      context.CreateBookmark(DocumentStatusChangeWatcher.DocumentPartnerSoftwareIntegrationStatusChangedBookmark, OnBookmarkResumed);
    }


    private void OnBookmarkResumed(NativeActivityContext context, Bookmark bookmark, object value)
    {
      if (value is PartnerSoftwareIntegrationStatus)
      {
        Status.Set(context, (PartnerSoftwareIntegrationStatus)value);
      }
    }

    protected override bool CanInduceIdle
    {
      get { return true; }
    }
  }

1 个答案:

答案 0 :(得分:1)

当您更改工作流定义并尝试恢复持久工作流时,您经常会看到这些奇怪的异常。

基本上,您无法对正在运行的工作流程进行任何更改。