在主工作流中使用子工作流

Using sub workflow inside main workflow

当我在内部使用另一个工作流程时,我以动态方式加载工作流程 XAML 时遇到问题。

我的主要工作流程 - MainWorkflow.xaml。在另一个工作流程中 - SubWorkflow.xaml 在 运行 时间,当我加载 Main.xaml 时出现以下错误:

{"CacheMetadata for activity 'FlowManager.Flows.MainWorkflow' through 'System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:FlowManager.Flows}SubWorkflow'

加载工作流的代码:

public object Load(Dictionary<string, object> inputs)
{
    object returnValue = null;

    ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
    {
        //since the workflow contains expression, the following flag must be set to true
        CompileExpressions = true
    };


    WorkflowApplication wfApp =
        new WorkflowApplication(
            ActivityXamlServices.Load(Path, settings), inputs)
        {
            Completed = delegate (WorkflowApplicationCompletedEventArgs e)
            {
                returnValue = e.Outputs["returnValue"];
                syncEvent.Set();
            },
            Idle = delegate (WorkflowApplicationIdleEventArgs e) { idleEvent.Set(); }                    
    };

    wfApp.Run();
    syncEvent.WaitOne();
    return returnValue;
}

通过创建 Main 的实例而不是通过加载 XAML 来更改工作流的加载,效果很好

        WorkflowApplication wfApp =
            new WorkflowApplication(new MainWorkflow(), inputs)

有什么办法解决这个问题吗?

找到答案,需要添加带有 XamlXmlReaderSettings 对象的程序集引用

    var xamlReaderSettings = new XamlXmlReaderSettings()
    {
        LocalAssembly = typeof(GetVmIp).Assembly
    };
    var reader = new XamlXmlReader(Path, xamlReaderSettings);


    WorkflowApplication wfApp =
        new WorkflowApplication(
            ActivityXamlServices.Load(reader, settings), inputs)

而且有效。