I have a problem loading workflow XAML in a dynamic way when I am using another workflow inside.
My main Workflow - MainWorkflow.xaml. having inside another workflow - SubWorkflow.xaml In run time When I load the Main.xaml am getting the following error:
{"CacheMetadata for activity 'FlowManager.Flows.MainWorkflow' through 'System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:FlowManager.Flows}SubWorkflow'
The code for loading the workflow:
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;
}
changing the loading of the workflow by creating an instance of Main and not by loading the XAML, works perfectly
WorkflowApplication wfApp =
new WorkflowApplication(new MainWorkflow(), inputs)
Any Ideas how I solve this problem?
Found the answer, needed to add an assembly reference with a XamlXmlReaderSettings object
var xamlReaderSettings = new XamlXmlReaderSettings()
{
LocalAssembly = typeof(GetVmIp).Assembly
};
var reader = new XamlXmlReader(Path, xamlReaderSettings);
WorkflowApplication wfApp =
new WorkflowApplication(
ActivityXamlServices.Load(reader, settings), inputs)
and it works.