Type initializer exception when displaying Workflow/sequential activity in designer

Hi,

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
}

[11655 byte] By [BFlynn] at [2007-12-25]
# 1
it works fine on my machine. what build are you on? if its one of the beta ones, try migrating to the RC5 one.
sergey.chub at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
The problems I am having seems to be my use of custom types generated by the svcutil tool in DependencyProperty's

Say I have an custom type generated by svcutil like

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4324.13")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://someuri")]
public partial class SomeSerializableObject
{
...
}wq

I then use this in the original example to define my custom activity.

If I include the custom activity in another workflow, when I try to load the workflow in the designer I get an exeption thrown by the workflows constructor.

Note that the origianl custom activity can be displayed without any problems.

Maybe I have to define a custom deserialiser for the designer.

BFlynn at 2007-9-3 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified