I've created a dependency property that's causing me some problems at runtime. First, the definition of the dependency property:
public static DependencyProperty ToValueProperty = System.Workflow.ComponentModel.DependencyProperty.Register("ToValue", typeof(object), typeof(SendEmailActivity));
[Description("To Email Address")]
[Category("EmailActivity")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public object ToValue
{
get
{
return ((object)(base.GetValue(SendEmailActivity.ToValueProperty)));
}
set
{
base.SetValue(SendEmailActivity.ToValueProperty, value);
}
}
public string To
{
get { return (string)ToValue; }
set { ToValue = value; }
}
I've modified the SendEmail activity from one of the hands on labs, so that it's To dependency property (renamed to ToValue) is of type object rather than string.
I set an activity reference on this to the property of a custom activity. Here's the reference as defined in the workflow designer file:
//
// EmailAccountManager
//
this.EmailAccountManager.Body = "email body";
this.EmailAccountManager.From = "aValidEmailAddress@somedomain.com";
this.EmailAccountManager.Name = "EmailAccountManager";
this.EmailAccountManager.Subject = "Your incident has been escalated";
activitybind3.Name = "SupportWorkflow2";
activitybind3.Path = "SystemServer";
this.EmailAccountManager.To = null;
activitybind4.Name = "LoadAccountManager";
activitybind4.Path = "DataSet.Tables[\"Phub Employee\"].Rows[0][\"Work_Email\"]";
this.EmailAccountManager.SetBinding(MTActivities.SendEmailActivity.ToValueProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind4)));
this.EmailAccountManager.SetBinding(MTActivities.SendEmailActivity.SystemServerProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind3)));
Of note above is activityBind4. LoadAccountManger is the name of a custom activity. The path property points to a DataSet object exposed on the activity, and specifically to a particular field's value. This resolves to something of type System.Object.
At design time, there is no problem. At runtime, when I run the code, the ToValue property getter fails with this error message:
System.FormatException occurred
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
If I ignore the exceptions a few times, the code will continue and finish sucessfully.
I've copied most of the huge call stack below. The question I have is, what can I do determine what the problem is
Thanks,
Notre
Call stack:
mscorlib.dll!System.Number.StringToNumber(string str, System.Globalization.NumberStyles options, ref System.Number.NumberBuffer number, System.Globalization.NumberFormatInfo info, bool parseDecimal) + 0x108 bytes
mscorlib.dll!System.Number.ParseInt32(string s, System.Globalization.NumberStyles style = AllowLeadingWhite | AllowTrailingWhite | AllowLeadingSign, System.Globalization.NumberFormatInfo info) + 0x67 bytes
mscorlib.dll!string.System.IConvertible.ToInt32(System.IFormatProvider provider) + 0x2c bytes
mscorlib.dll!System.Convert.ChangeType(object value, System.Type conversionType, System.IFormatProvider provider) + 0xd7 bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.BindHelpers.MatchIndexerParameters(System.Reflection.PropertyInfo propertyInfo, string[] argNames = {Dimensions:[1]}, object[] args = {Dimensions:[1]}) + 0x184 bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.BindHelpers.GetMatchedPropertyInfo(System.Type memberType, string[] aryArgName = {Dimensions:[1]}, object[] args = {Dimensions:[1]}) + 0x16e bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.PathWalker.TryWalkPropertyPath(System.Type rootType, string path) + 0x3ac bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.MemberBind.GetMemberInfo(System.Type srcType, string path) + 0xa3 bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.ActivityBind.GetMemberInfo(System.Type dataSourceType = {Name = "LoadDataActivity" FullName = "MTActivities.LoadDataActivity"}, string path = "DataSet.Tables[\"Phub Employee\"].Rows[0][\"Work_Email\"]", System.Type targetType = {Name = "Object" FullName = "System.Object"}) + 0x1c bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.ActivityBind.InternalGetRuntimeValue(System.Workflow.ComponentModel.Activity activity = {EmailAccountManager [MTActivities.SendEmailActivity]}, System.Type targetType = {Name = "Object" FullName = "System.Object"}) + 0x3c bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.ActivityBind.GetRuntimeValue(System.Workflow.ComponentModel.Activity activity, System.Type targetType) + 0x1f bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.DependencyObject.GetBoundValue(System.Workflow.ComponentModel.ActivityBind bind, System.Type targetType) + 0x2d bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.DependencyObject.GetValueCommon(System.Workflow.ComponentModel.DependencyProperty dependencyProperty = {ToValue}, System.Workflow.ComponentModel.PropertyMetadata metadata) + 0xe6 bytes
System.Workflow.ComponentModel.dll!System.Workflow.ComponentModel.DependencyObject.GetValue(System.Workflow.ComponentModel.DependencyProperty dependencyProperty) + 0x42 bytes
> MTActivities.dll!MTActivities.SendEmailActivity.ToValue.get() Line 53 + 0xd bytes C#
MTActivities.dll!MTActivities.SendEmailActivity.To.get() Line 63 + 0x9 bytes C#
MTActivities.dll!MTActivities.SendEmailActivity.Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext = {System.Workflow.ComponentModel.ActivityExecutionContext}) Line 123 + 0x7 bytes C#

Tips in debugging dependency property problem?
ANDYPLIRA
Tom and Vishal:
I took the example Vishal put together and it does 'work' for me as well under Beta 2. The only problem is when I run it under the debugger and observe the Debug output window. There are messages like this:
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll.
If I check the Thrown exceptions for 'Common Language Runtime Exceptions', then the debugger breaks when trying to evaluate the get for MyString property. There are other times when this exception is thrown too, in the example provided by Vishal.
Perhaps I'm being unreasonable, as these are all first chance exceptions
Notre
GregVance
What build of Windows Workflow Foundation are you running this on
Make sure that the table name and column name are correct in your binding. I have a pared down example attached that does the same and works fine on Beta2.2 version of the product.
TestActivity.cs:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace DataSetBinding
{
public partial class TestActivity : Activity
{
public TestActivity()
{
InitializeComponent();
}
public static DependencyProperty MyStringProperty = System.Workflow.ComponentModel.DependencyProperty.Register("MyString", typeof(object), typeof(TestActivity));
[Description("String Property")]
[Category("Misc.")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public object MyString
{
get
{
return (base.GetValue(TestActivity.MyStringProperty));
}
set
{
base.SetValue(TestActivity.MyStringProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
Console.WriteLine(MyString as string);
return ActivityExecutionStatus.Closed;
}
}
}
TestActivity.designer.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace DataSetBinding
{
public partial class TestActivity
{
#region Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
[System.Diagnostics.DebuggerNonUserCode]
private void InitializeComponent()
{
//
// TestActivity
//
this.Name = "TestActivity";
}
#endregion
}
}
Workflow1.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Data;
namespace DataSetBinding
{
public sealed partial class Workflow1: SequentialWorkflowActivity
{
public DataSet dataSetObject;
public Workflow1()
{
InitializeComponent();
dataSetObject = new DataSet("TestDataSet");
dataSetObject.Tables.Add("TestTable");
dataSetObject.Tables["TestTable"].Columns.Add("TestColumn");
dataSetObject.Tables["TestTable"].Columns["TestColumn"].DataType = typeof(string);
dataSetObject.Tables["TestTable"].Rows.Add(new object[] { "Hello World" });
}
}
}
Workflow1.designer.cs
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace DataSetBinding
{
partial class Workflow1
{
#region Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
[System.Diagnostics.DebuggerNonUserCode]
private void InitializeComponent()
{
this.CanModifyActivities = true;
System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind();
this.testActivity1 = new DataSetBinding.TestActivity();
//
// testActivity1
//
activitybind1.Name = "Workflow1";
//activitybind1.Path = "dataSetObject.Tables[\"TestTable\"].Rows[0].ItemArray[0]";
activitybind1.Path = "dataSetObject.Tables[\"TestTable\"].Rows[0][\"TestColumn\"]";
this.testActivity1.Name = "testActivity1";
this.testActivity1.SetBinding(DataSetBinding.TestActivity.MyStringProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));
//
// Workflow1
//
this.Activities.Add(this.testActivity1);
this.Name = "Workflow1";
this.CanModifyActivities = false;
}
#endregion
private TestActivity testActivity1;
}
}
PKH
Hi Vishal,
I'm using Beta2. Maybe this will work when I upgrade to Beta 2.2. I'm pretty sure that table and column names are correct in my binding.
Notre
BLOX