Run Workflow with nested XAML-activity

253 Views Asked by At

I need to run workflow XAML, but that workflow keeps references to other XAMLs. When I'm trying to run the workflow by

ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
{
    CompileExpressions = true
};
return ActivityXamlServices.Load(stream, settings);

I get next error from Load method:

CacheMetadata for activity 'MyNamespace.MyMainActivity' threw 'System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:MyNamespace}MyNestedActivity'.

How can I solve it?

1

There are 1 best solutions below

0
raj2sudha On

I think you have to convert your internal xamls to dll (assembly) file. And load the assembly file while reading/loading the parent xaml.

System.Xaml.XamlXmlReaderSettings xmlsettings = new System.Xaml.XamlXmlReaderSettings();
        if(dllFile != null) { 
            Assembly wfAssembly = Assembly.Load(dllFile);
            xmlsettings.LocalAssembly = wfAssembly;
        }

        System.IO.StringReader stringReader = new System.IO.StringReader(xaml);
        XamlXmlReader reader = new XamlXmlReader(stringReader, xmlsettings);
        ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings { CompileExpressions = true };
        Activity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(reader, settings);

hope this helps.