当我在其中使用其他工作流程时,我以动态方式加载工作流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)
任何想法我如何解决这个问题?
答案 0 :(得分:0)
找到答案,需要使用XamlXmlReaderSettings对象添加程序集引用
var xamlReaderSettings = new XamlXmlReaderSettings()
{
LocalAssembly = typeof(GetVmIp).Assembly
};
var reader = new XamlXmlReader(Path, xamlReaderSettings);
WorkflowApplication wfApp =
new WorkflowApplication(
ActivityXamlServices.Load(reader, settings), inputs)
它有效。