0

我需要运行工作流 XAML,但该工作流保留对其他 XAML 的引用。当我尝试通过以下方式运行工作流程时

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

我从 Load 方法得到下一个错误:

活动“MyNamespace.MyMainActivity”的 CacheMetadata 抛出“System.Xaml.XamlObjectWriterException:无法创建未知类型“{clr-namespace:MyNamespace}MyNestedActivity”。

我该如何解决?

4

1 回答 1

0

我认为您必须将内部 xamls 转换为 dll(程序集)文件。并在读取/加载父 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);

希望这可以帮助。

于 2016-01-08T06:17:40.560 回答