WorkflowInspectionServices 在 Workflow Foundation 中向我抛出 XamlObjectWriterException

发布于 2024-11-01 07:17:55 字数 2589 浏览 1 评论 0原文

对于一个简单的原型,我必须显示一个工作流程文件,并显示我们实际上处于哪个步骤。

我在这里找到了一个示例: http://msdn.microsoft.com/en-us /library/ee624139.aspx

这几乎满足了我的需要。

在此示例中,所有操作都不会等待另一个操作。所以我为自己创建了一些非常虚拟的活动:

    public class WaitForNextCall :NativeActivity
{
    public const String WaitBookmark = "WaitingStep";


    #region Overrides of NativeActivity

    /// <summary>
    /// When implemented in a derived class, runs the activity’s execution logic.
    /// </summary>
    /// <param name="context">The execution context in which the activity executes.</param>
    protected override void Execute(NativeActivityContext context)
    {
        context.CreateBookmark(WaitBookmark);
    }

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

这似乎有效。从那时起,我直接在代码中创建工作流程:

            return new Sequence()
                   {
                       Activities =
                           {
                               new WaitForNextCall(){DisplayName = "Step one"},
                               new WaitForNextCall(){DisplayName = "Step Two"},
                               new WaitForNextCall(){DisplayName = "Step Three"},
                               new WaitForNextCall(){DisplayName = "Step Four"}
                           }
                   };

唯一的问题是我在工作流程设计器中只看到“序列”元素。

所以我创建了一个 xaml 文件,它描述了完全相同的事情,然后我像这样加载它:

return ActivityXamlServices.Load("Workflows/WorkflowSample.xaml") as DynamicActivity;

但是后来我得到了这个异常:

    System.Xaml.XamlObjectWriterException occurred
  Message=Impossible de créer le type inconnu '{clr-MyTestNameSpace.UserInterface.WorkflowItems}WaitForNextCall'.
  Source=System.Xaml
  LineNumber=0
  LinePosition=0
  StackTrace:
       à System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
       à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       [...] 

我仔细检查了,文件存在(看起来,当文件不存在时,还有另一个错误消息t 指定正确)。但它找不到我的“WaitFornextCall”类,该类仅在下面几行中使用。

我有点绝望,我试图了解工作流基础是如何工作的,但现在有点困难:(

欢迎任何建议

编辑: 我尝试这样做来读取文件,我的构造函数中没有任何异常,但我不知道为什么,我正在使用的一些库(ActiPro)似乎在加载后不再工作:

        XamlReader reader = new XamlXmlReader("Workflows/WorkflowSample.xaml", new XamlXmlReaderSettings(){LocalAssembly =  System.Reflection.Assembly.GetExecutingAssembly()});

        return ActivityXamlServices.Load(reader);

For a simple prototype, I've to display a workflow file, and show on which step we are actually.

I found a sample here: http://msdn.microsoft.com/en-us/library/ee624139.aspx

Which does almost what I need.

In this sample, all action never wait on another action. So I created myself some very dummy Activity:

    public class WaitForNextCall :NativeActivity
{
    public const String WaitBookmark = "WaitingStep";


    #region Overrides of NativeActivity

    /// <summary>
    /// When implemented in a derived class, runs the activity’s execution logic.
    /// </summary>
    /// <param name="context">The execution context in which the activity executes.</param>
    protected override void Execute(NativeActivityContext context)
    {
        context.CreateBookmark(WaitBookmark);
    }

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

Which seems to work. Since there I was creating my workflow directly in-code:

            return new Sequence()
                   {
                       Activities =
                           {
                               new WaitForNextCall(){DisplayName = "Step one"},
                               new WaitForNextCall(){DisplayName = "Step Two"},
                               new WaitForNextCall(){DisplayName = "Step Three"},
                               new WaitForNextCall(){DisplayName = "Step Four"}
                           }
                   };

The only problem with that is that I only see a "Sequence" element in the workflow designer.

So I created a xaml file which describe exactily the same thing, and I load it like this:

return ActivityXamlServices.Load("Workflows/WorkflowSample.xaml") as DynamicActivity;

But then I got this exception:

    System.Xaml.XamlObjectWriterException occurred
  Message=Impossible de créer le type inconnu '{clr-MyTestNameSpace.UserInterface.WorkflowItems}WaitForNextCall'.
  Source=System.Xaml
  LineNumber=0
  LinePosition=0
  StackTrace:
       à System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
       à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       [...] 

I double-checked, the file is present(it appears, that there is another error message when file isn't specified correctly). But it cannot find my "WaitFornextCall" class, which is used just several lines below.

I'm a little desesperate, I'm trying to understand how works Workflow foundations, but it's a little hard for now :(

Any advice will be welcome

Edit:
I tried this to read the file, I don't have any exception in my constructor, but I don't know why, some libraries I'm using(ActiPro) seems to doesn't work anymore after the load:

        XamlReader reader = new XamlXmlReader("Workflows/WorkflowSample.xaml", new XamlXmlReaderSettings(){LocalAssembly =  System.Reflection.Assembly.GetExecutingAssembly()});

        return ActivityXamlServices.Load(reader);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是偏爱你 2024-11-08 07:17:55

我找到了解决办法!!!!

YEAAAAAAAAAAAAAH :P

事实上,问题是我的工作流程与我的自定义活动位于同一个项目中。然后,Visual Studio不会指示设计者可以在哪个程序集中找到此活动,但是当您读取文件时,这是一个独立的阅读器,它不知道您当前的程序集。

因此,有两个不同的项目,一个包含工作流,一个包含活动,然后我的工作流指定我可以在其中找到图表的程序集。像这样我可以轻松地执行 WorkflowDesigner.Load("myWorkflowHere.xaml");没有任何问题!

I found the solution !!!!

YEAAAAAAAAAAAAAH :P

In fact the problem is that my Workflow was in the same project than my custom activity. And then visual studio doesn't indicate in which assembly the designer could found this activity, but when you read the file, this is an independant reader, which doesn't know you current assembly.

So having TWO different project, one containing the workflow, one containing activities, and then my workflow specify the assembly in which I can found the chart. Like this I can easily do a WorkflowDesigner.Load("myWorkflowHere.xaml"); without any problem!

夜司空 2024-11-08 07:17:55

“Workflows/WorkflowSample.xaml”可能是针对您的代码的早期版本构建的。

删除它,重建您的解决方案,然后重新创建它。

"Workflows/WorkflowSample.xaml" probably was built against a prior version of your code.

Delete it, rebuild your solution, then recreate it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文