G
Guest
Setup:
I have a C# 2.0 Conrol Library project and a Windows Form project in a
solution. I am developing winform controls in teh library and the winform
project has just a single form for testing these controls. The library
project is referenced by the winform proect using a project reference rather
than a static dll.
Some of my controls require custom TypeConverters, basically so I can sort
the properties and handle string to control conversions, etc... I actually
derive from ExpandableObjectConverter to take advantage of some of the extra
features of that type,specifically relating to PropertyGrid usage.
Problem:
If I drop one of my controls on the test form, everything works just fine.
However, if I make any changes whatsoever to the control, even if it is to
add a comment, and recompile, the control is no longer able to serialize
properties of the type that is using my custom converter. I get errors such
as the following:
"Code generation for property 'TabStyle' failed. Error
was:''SuperTabStyleConverter' is unable to convert
'INTZControls.SuperTabStyle' to
'System.ComponentModel.Design.Serialization.InstanceDescriptor'.'"
I also occasionally get the following error:
"Unable to cast object of type 'INTZControls.Tabstrip3D' to type
'INTZControls.TabStrip3D'."
I assume the second one is due to the fact that the controls are no longer
binary compatible, but this is just a guess. The first one just blows my
mind. If I do a full recompile, shut and restart VS2005, everything works
again. The other concern I have is that this code runs without any problems
within VS2003, even after making significant changes to the control source.
Here is an example of one of my type converters:
public class TextStyleConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type
destinationType)
{
if ((destinationType == typeof(InstanceDescriptor)) || (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(InstanceDescriptor))
{
ConstructorInfo ci = typeof(TextStyle).GetConstructor(new Type[] { });
if (ci != null)
{
return new InstanceDescriptor(ci, null, false);
}
}
else if (destinationType == typeof(string))
{
return value.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
return TextStyle.Parse(value.ToString());
}
return base.ConvertFrom(context, culture, value);
}
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext
context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext
context)
{
return true;
}
}
Here is the definition of the class that uses this converter:
[TypeConverter(typeof(TextStyleConverter))]
public class TextStyle
{
///
}
Here is the property in the control that uses this class:
[Category("Appearance"), Browsable(true), Description("The text style used
to display the items in the control"),
DefaultValue(typeof(TextStyle), "Microsoft Sans Serif,
8.25pt;ControlText;MiddleCenter;Normal"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TextStyle DefaultTextStyle
{
get
{
return m_DefaultTextStyle;
}
protected set
{
m_DefaultTextStyle = value;
this.Refresh();
}
}
Ideas?
I have a C# 2.0 Conrol Library project and a Windows Form project in a
solution. I am developing winform controls in teh library and the winform
project has just a single form for testing these controls. The library
project is referenced by the winform proect using a project reference rather
than a static dll.
Some of my controls require custom TypeConverters, basically so I can sort
the properties and handle string to control conversions, etc... I actually
derive from ExpandableObjectConverter to take advantage of some of the extra
features of that type,specifically relating to PropertyGrid usage.
Problem:
If I drop one of my controls on the test form, everything works just fine.
However, if I make any changes whatsoever to the control, even if it is to
add a comment, and recompile, the control is no longer able to serialize
properties of the type that is using my custom converter. I get errors such
as the following:
"Code generation for property 'TabStyle' failed. Error
was:''SuperTabStyleConverter' is unable to convert
'INTZControls.SuperTabStyle' to
'System.ComponentModel.Design.Serialization.InstanceDescriptor'.'"
I also occasionally get the following error:
"Unable to cast object of type 'INTZControls.Tabstrip3D' to type
'INTZControls.TabStrip3D'."
I assume the second one is due to the fact that the controls are no longer
binary compatible, but this is just a guess. The first one just blows my
mind. If I do a full recompile, shut and restart VS2005, everything works
again. The other concern I have is that this code runs without any problems
within VS2003, even after making significant changes to the control source.
Here is an example of one of my type converters:
public class TextStyleConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type
destinationType)
{
if ((destinationType == typeof(InstanceDescriptor)) || (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(InstanceDescriptor))
{
ConstructorInfo ci = typeof(TextStyle).GetConstructor(new Type[] { });
if (ci != null)
{
return new InstanceDescriptor(ci, null, false);
}
}
else if (destinationType == typeof(string))
{
return value.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
return TextStyle.Parse(value.ToString());
}
return base.ConvertFrom(context, culture, value);
}
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext
context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext
context)
{
return true;
}
}
Here is the definition of the class that uses this converter:
[TypeConverter(typeof(TextStyleConverter))]
public class TextStyle
{
///
}
Here is the property in the control that uses this class:
[Category("Appearance"), Browsable(true), Description("The text style used
to display the items in the control"),
DefaultValue(typeof(TextStyle), "Microsoft Sans Serif,
8.25pt;ControlText;MiddleCenter;Normal"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TextStyle DefaultTextStyle
{
get
{
return m_DefaultTextStyle;
}
protected set
{
m_DefaultTextStyle = value;
this.Refresh();
}
}
Ideas?