Type initializer exception when displaying Workflow/sequential activity in designer
I have created a number of custom activites which are defined in a single .cs file. I can add these activities to a workflow or sequential activity without any problems. If I build the code there are now build errors generated bur if I exit the designer view of the workflow/sequential activity and re-enter it I get an error saying that the type initialisr for the cutom activities are throwing exceptions. I have used the .net samples as a template for my custom activities. Has anyone seen this behaviour before. I have included an example of a custom activity I am using.
[ToolboxItemAttribute(typeof(ActivityToolboxItem))]
public partial class ExampleActivity : System.Workflow.ComponentModel.Activity
{
public ExampleActivity()
{
InitializeComponent();
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
{
this.RaiseEvent(InvokingEvent, this, new EventArgs());
// Call some method
this.RaiseEvent(InvokedEvent, this, new EventArgs());
return ActivityExecutionStatus.Closed;
}
public static DependencyProperty SomVarProperty = System.Workflow.ComponentModel.DependencyProperty.Register("SomVar", typeof(SomeSerializableObject), typeof(ExampleActivity));
[Description("This is the description which appears in the Property Browser")]
[Category("This is the category which will be displayed in the Property Browser")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public SomeSerializableObject SomVar
{
get
{
return ((SomeSerializableObject)(base.GetValue(ExampleActivity.SomVarProperty)));
}
set
{
base.SetValue(ExampleActivity.SomVarProperty, value);
}
}
public static DependencyProperty InvokingEvent = DependencyProperty.Register("Invoking", typeof(EventHandler), typeof(ExampleActivity));
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[Category("Handlers")]
public event EventHandler Invoking
{
add
{
base.AddHandler(ExampleActivity.InvokingEvent, value);
}
remove
{
base.RemoveHandler(ExampleActivity.InvokingEvent, value);
}
}
public static DependencyProperty InvokedEvent = DependencyProperty.Register("Invoked", typeof(EventHandler), typeof(ExampleActivity));
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[Category("Handlers")]
public event EventHandler Invoked
{
add
{
base.AddHandler(ExampleActivity.InvokedEvent, value);
}
remove
{
base.RemoveHandler(ExampleActivity.InvokedEvent, value);
}
}
}
public partial class ExampleActivity
{
#region Activity Designer generated code
[System.Diagnostics.DebuggerNonUserCode()]
private void InitializeComponent()
{
this.Name = "ExampleActivity";
}
#endregion
}

