TypeConverter derivations failing to convert to InstanceDescriptor

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?
 
B

Bob Powell [MVP]

Have you by any strange circumstance turned on the automatic versioning by
putting an asterisk in the version number? If you have, turn that off and
you may find that your pain goes away...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Bruce S said:
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?
 
G

Guest

Thanks for the reply.

The versions are set as follows:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

I made those static at the time I created the solution.

I should also say that I don't seem to have the same problems when I use the
Microsoft designed TypeConverters - I just don't get the custom behavior I
need. This leads me to believe it has something to do with recompiling. It
is almost as if the IDE is looking for the TypeConverter from a previous
build. Again, what is really frustrating is that the EXACT code in VS2003
never causes any problems. As a matter of fact, these classes were written
in VS2003 and I copied the cs files to the new solution directory and
included them in the project. I thought that might have been the problem, so
I removed those files and created them from scratch, and just copied the code
function-by-function instead. Same problems.

Bruce S


Bob Powell said:
Have you by any strange circumstance turned on the automatic versioning by
putting an asterisk in the version number? If you have, turn that off and
you may find that your pain goes away...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Bruce S said:
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?
 
B

Bob Powell [MVP]

I was thinking on the lines that the code was looking for a specific
version. Have you perchance signed the dev versions? it might be a good idea
to remove strong names until the initial dev cycle is over...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Bruce S said:
Thanks for the reply.

The versions are set as follows:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

I made those static at the time I created the solution.

I should also say that I don't seem to have the same problems when I use
the
Microsoft designed TypeConverters - I just don't get the custom behavior I
need. This leads me to believe it has something to do with recompiling.
It
is almost as if the IDE is looking for the TypeConverter from a previous
build. Again, what is really frustrating is that the EXACT code in VS2003
never causes any problems. As a matter of fact, these classes were
written
in VS2003 and I copied the cs files to the new solution directory and
included them in the project. I thought that might have been the problem,
so
I removed those files and created them from scratch, and just copied the
code
function-by-function instead. Same problems.

Bruce S


Bob Powell said:
Have you by any strange circumstance turned on the automatic versioning
by
putting an asterisk in the version number? If you have, turn that off and
you may find that your pain goes away...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Bruce S said:
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?
 
G

Guest

Still unsigned. I never sign until ready for a release candidate.

Bruce

<REMOVED PREVIOUS POSTS>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top