我(动态)调用工作流时遇到以下异常:


  处理工作流树时遇到以下错误:
  'DynamicActivity':活动'1:DynamicActivity'的私有实现具有以下验证错误:处理表达式“ TryCast(simplerule_out,OutputBase2)”时遇到编译器错误。
  未定义类型“ OutputBase2”。
  
  'DynamicActivity':活动'1:DynamicActivity'的私有实现具有以下验证错误:编译器错误遇到处理表达式“ Res”。
  未定义类型“ OutputBase2”。
  
  'DynamicActivity':活动'1:DynamicActivity'的私有实现具有以下验证错误:编译器错误遇到处理表达式“ Res”。
  未定义类型“ OutputBase2”。
  
  'DynamicActivity':活动'1:DynamicActivity'的私有实现具有以下验证错误:编译器错误遇到处理表达式“ New List(Of OutputBase2)”的情况。
  未定义类型“ OutputBase2”。


工作流程非常简单,并且在VS 2010 beta 2上运行良好!

我要做的就是创建我的抽象自定义类型“ OutputBase2”的新列表。

public class OutputBase2
{
    public OutputBase2() { }

    public bool Succeeded { get; set; }
}

class Example
{
    public void Exec()
    {
        ActivityBuilder builder = new ActivityBuilder();
        builder.Name = "act1";
        var res = new DynamicActivityProperty { Name = "Res", Type = typeof(OutArgument<List<OutputBase2>>), Value = new OutArgument<List<OutputBase2>>() };
        builder.Properties.Add(res);
        builder.Implementation = new Sequence();
        ((Sequence)builder.Implementation).Activities.Add(new Assign<List<OutputBase2>> { To = new VisualBasicReference<List<OutputBase2>> { ExpressionText = res.Name }, Value = new VisualBasicValue<List<OutputBase2>>("New List(Of OutputBase2)") });
        Activity act = getActivity(builder);

        var res2 = WorkflowInvoker.Invoke(act);
    }

    string getXamlStringFromActivityBuilder(ActivityBuilder activityBuilder)
    {
        string xamlString;
        StringBuilder stringBuilder = new StringBuilder();
        System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder);
        System.Xaml.XamlSchemaContext xamlSchemaContext = new System.Xaml.XamlSchemaContext();
        System.Xaml.XamlXmlWriter xamlXmlWriter = new System.Xaml.XamlXmlWriter(stringWriter, xamlSchemaContext);
        System.Xaml.XamlWriter xamlWriter = System.Activities.XamlIntegration.ActivityXamlServices.CreateBuilderWriter(xamlXmlWriter);
        System.Xaml.XamlServices.Save(xamlWriter, activityBuilder);
        xamlString = stringBuilder.ToString();
        return xamlString;
    }

    public Activity getActivity(ActivityBuilder t)
    {
        string xamlString = getXamlStringFromActivityBuilder(t);
        System.IO.StringReader stringReader = new System.IO.StringReader(xamlString);
        Activity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(stringReader);
        return activity;
    }
}


谢谢!

最佳答案

解决方案是在执行活动时添加“ VisualBasicSettings”实例。

这个线程很有用:
http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/2b77771e-84a6-4ec3-a944-3de2a60201fc

关于c# - WF4 RC的“类型未定义”异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2811724/

10-11 06:26