WF4 RC的“未定义类型”异常

时间:2010-05-11 14:52:55

标签: c# .net c#-4.0 workflow-foundation-4

在调用我的工作流程(动态)时,我得到以下异常:

  

处理工作流树时遇到以下错误:   '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;
    }
}

谢谢!

1 个答案:

答案 0 :(得分:0)

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

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