Undefined Exception with WF4 RC
When calling my workflow (dynamically) I get the following exception:
The following errors were encountered while processing the workflow tree: "DynamicActivity": private activity implementation "1: DynamicActivity" has the following validation error: compiler error encounters processing expression "TryCast (simplerule_out, OutputBase2)". The type 'OutputBase2' is undefined.
"DynamicActivity": Private implementation of activity "1: DynamicActivity" has the following validation error: Compiler error encounters "Res" processing expression. The type 'OutputBase2' is undefined.
"DynamicActivity": Private implementation of activity "1: DynamicActivity" has the following validation error: Compiler error encounters "Res" processing expression. The type 'OutputBase2' is undefined.
"DynamicActivity": Private implementation of activity "1: DynamicActivity" has the following validation error: compiler error (s) encountered a processing expression "New list (OutputBase2)". The type 'OutputBase2' is undefined.
The workflow is very simple and works great on VS 2010 beta 2!
All I'm trying to do is create a new list of my abstract custom type "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;
}
}
Thanks!
a source to share
The solution is to add an instance of VisualBasicSettings when performing an action.
This thread was helpful:
http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/2b77771e-84a6-4ec3-a944-3de2a60201fc
a source to share