Windows Workflow Foundation 3


Ui custom activity property unvalid error


hi,all
when I developed  a custom sendEmailActivity, I had a property that named "EmailBody" in the activity, it is optional as like Condition which is property in IfElseActivity.
I used TemplateEmailBody and NormalEmailBody to support EmailBody property
two classes are inherit from EmailBody, it's a abstract class that code as follow:
    [TypeConverter(typeof(EmailBodyConverter))]    public abstract class EmailBody     {        public abstract string Get();    }
    public class NormalEmailBody : EmailBody    {        private string _value;        public string Value        {            get { return _value; }            set { _value = value; }        }        public override string Get()        {            return _value;        }    }
 public class TemplateEmailBody : EmailBody {        private Dictionary<string,object> _parameters;        private DataSet _data;        private string _templatePath;        public Dictionary<string,object> Parameters        {            get { return _parameters; }            set { _parameters = value; }        }        public DataSet Data        {            get { return _data; }            set { _data = value; }        }        [EditorAttribute(typeof(FileNameEditor), typeof(UITypeEditor))]        public string TemplatePath        {            get { return _templatePath; }            set { _templatePath = value; }        }        public override string Get()        {            string bodyContent = GenerateBodyContent(_data, _parameters, _templatePath);
            return bodyContent;        }        // Transform body by template(xslt)        private string GenerateBodyContent(DataSet bodyData, Dictionary<string, object> parameterValues, string  bodyTemplate)        {            ......................        }            }
The TypeConverter  code is:
    public class EmailBodyConverter : ExpandableObjectConverter     {        private static StandardValuesCollection _defaultStandard;        static EmailBodyConverter()        {            ArrayList list = new ArrayList();            list.Add(new TemplateEmailBody());            list.Add(new NormalEmailBody());            _defaultStandard = new StandardValuesCollection(list);        }        public EmailBodyConverter()        {        }        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)        {            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));        }        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)        {            object obj = null;            if (value!=null)            {                Type type = Type.GetType(value.ToString());                obj = Activator.CreateInstance(type);                if (obj is TemplateEmailBody)                {                    TemplateEmailBody emailBody = obj as TemplateEmailBody;
                    emailBody.Data = new System.Data.DataSet();                    emailBody.Parameters = new Dictionary<string, object>();                    return emailBody;                }            }            return obj;        }        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)        {            if (destinationType == typeof(string))            {                return true;            }            return base.CanConvertTo(context, destinationType);        }        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)        {                      if (destinationType == typeof(string) && value is NormalEmailBody)            {                NormalEmailBody body = value as NormalEmailBody;                // simply build the string as type full name                return body.GetType().FullName;            }            if (destinationType == typeof(string) && value is TemplateEmailBody)            {                TemplateEmailBody body = value as TemplateEmailBody;                // simply build the string as type full name                return body.GetType().FullName;            }            return base.ConvertTo(context, culture, value, destinationType);        }        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)        {            return true;        }        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)        {            return true;        }        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)        {            return _defaultStandard;        }    }
I used it in my custom Activity as follow
        public static DependencyProperty EmailBodyProperty = System.Workflow.ComponentModel.DependencyProperty.Register("EmailBody", typeof(EmailBody), typeof(SendEmailActivity));
        [Description("The body of Email")]        [Category("EmailSettings")]        [Browsable(true)]        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]        public EmailBody EmailBody        {            get            {                return ((EmailBody)(base.GetValue(SendEmailActivity.EmailBodyProperty)));            }            set            {                base.SetValue(SendEmailActivity.EmailBodyProperty, value);            }        }
The SendEmailActivity work is Ok, as my expected it is work as condition of IfElseActivity,
but when I use the activity in workflow, at first run it,it is ok,
secondary, i want to changed it, it throw a error in design-time the error details is:
 Object of type 'Company.Projects.Workflow.ExtendedActivity.NormalEmailBody' cannot be converted to type 'Company.Projects.Workflow.ExtendedActivity.EmailBody'.
why, it is sure that can be converted,but why throw this exception,
Anybody who can reply me? or who can tell me how to debug in designed-time?
thanks!
 
Hi,
 
Have you tried attaching your Visual Studio debugger to your designer?
 
Thanks,
Maggie
Hi,
 
Have you tried attaching your Visual Studio debugger to your designer?
 
Thanks,
Maggie
yes, I had been attached debugger to designer, but I did resolved it  yet

Related Links

invoke sub StateMachine workflow
Using WWF to model and support "Tech Trees" in RTS games
RuleConditionDialog and intellisense
Workflow Persistence & Event Arguments
PersistenceService - Transaction Timeout
SimpleExpenseReport
SQLTrackingQuery from Workflow
CreateWorkflow failing validation
xbox live mic help
download code samples of Microsoft press' windows workflow foundation step by step - Kenn Scribner
Advantage and disadvantage of ASP.NET WorkFl
When do activities CANCEL and How do i force activities to cancel state?
Windows workflow 4.0 persistent issues
Windows Workflow 4
help needed in state machine workflow in asp.net
About the Role in WWF

Categories

MSDN
Microsoft Office for D...
Commerce Server
SQL Server
Windows Embedded Compact
Dynamics
Development
Visio 2010
Project Server
Exchange Server
Unified Communications
Silverlight
Expression
Other Forums
Archived Forums A-B
Archived Forums SA-SM
Archived Forums Visual...
Windows Phone Preview ...
Microsoft Partner Center
Skype for Business
Microsoft R
Suggestions and Feedba...
MSBuild
Test Tools in Visual S...
Application Insights (AI)
Store Engagement Frame...
Application Compatibil...
General Windows Deskto...
Microsoft Message Queu...
Windows Desktop Optica...
Peer-to-Peer Networkin...
Windows Desktop Winsoc...
Windows Desktop Ribbon...
Windows Hardware Testi...
SharePoint Legacy Vers...
Cloud Services (Web an...
Service Bus
Azure Media Services
Azure App Service - We...
Azure Automation
Azure Key Vault
Azure Mobile Engagement
Azure Logic Apps
Azure SQL Data Warehouse
Azure Disk Encryption
Azure Log Integration
Common Language Runtim...
Team Foundation Server...
Team Foundation Server...
BizTalk Server RFID
TPL Dataflow
JScript Native
Microsoft Robotics - S...
SQL Server XML
SQL Server Application...
SQL Server 2012 PowerP...
SQL Server 2012 High A...
SQL Server 2012 Spatia...
SQL Server 2012 SQL To...
Bing Maps: Map Control...
Dynamics 365 for Custo...
Orchard - Help and Sup...
Speech Service for Dev...
Office Protocols
Hosting and Streaming ...
Managed Extensibility ...
Performance Profiling ...
WCF RIA Services with ...
Silverlight Video and ...
Surface Application De...
Retired SharePoint Soc...
Acropolis
Audio API and Programm...
Azure Startups
Core Coding Experience...
LightSwitch HTML Clien...
Managed Extensibility ...
Microsoft Security Dev...
MS-Build, Multi-Target...
Microsoft "Data Explor...
Parallel Computing Pla...
Performance Counters f...
Popfly Bugs and Sugges...
Parallel Programming w...
Service Bus EAI & EDI ...
SQL Creation
SQL Server 2014 Analys...
Team Foundation Server...
Team Foundation Server...
Tellme Studio (retired)
Tools for Windows Stor...
Visual C++ Express Edi...
Visual Studio Applicat...
Visual Studio Class De...
Visual Studio Code Ana...
Visual Studio WPF/SL D...
Web Development in Vis...
Windows Error Reportin...
Windows Live Controls ...
Windows MultiPoint Mou...
XML in Visual Studio a...
XML Paper Specificatio...
XNA Framework
Reporting
Windows Phone Preview ...
Skype Web SDK

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile