![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I get StackOverflow when I return an InstanceDescriptor which represents a constructor which takes it's own type as parameter. Could someone explain why return new InstanceDescriptor(ci,new object[]{date}); causes StackOverflow? Is it again going into the ConvertTo? Why? Short code snippet: if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } Full sample code: public class Component1 : System.ComponentModel.Component { public Component1(System.ComponentModel.IContainer container) { container.Add(this); } public Component1(){} private ExtendedDate _date; public ExtendedDate ExtendedDate { get { return _date; } set { _date = value; } } bool ShouldSerializeExtendedDate() { return true; } } [TypeConverter(typeof(ExtendedDateTypeConverter))] public class ExtendedDate { public ExtendedDate(ExtendedDate date) { } } internal sealed class ExtendedDateTypeConverter: TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value is ExtendedDate) { if(destinationType == typeof(string)) return ((ExtendedDate)value).ToString(); else if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } } 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 new ExtendedDate(null); } return base.ConvertFrom (context, culture, value); } } |
#3
| |||
| |||
|
|
You can actually debug your code, and see where the overflow occurrs. Just attach one instance of the IDE with the source project for this code to an instance of the IDE trying to use your object. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OjP9mkB2EHA.2644 (AT) TK2MSFTNGP11 (DOT) phx.gbl... Hi, I get StackOverflow when I return an InstanceDescriptor which represents a constructor which takes it's own type as parameter. Could someone explain why return new InstanceDescriptor(ci,new object[]{date}); causes StackOverflow? Is it again going into the ConvertTo? Why? Short code snippet: if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } Full sample code: public class Component1 : System.ComponentModel.Component { public Component1(System.ComponentModel.IContainer container) { container.Add(this); } public Component1(){} private ExtendedDate _date; public ExtendedDate ExtendedDate { get { return _date; } set { _date = value; } } bool ShouldSerializeExtendedDate() { return true; } } [TypeConverter(typeof(ExtendedDateTypeConverter))] public class ExtendedDate { public ExtendedDate(ExtendedDate date) { } } internal sealed class ExtendedDateTypeConverter: TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value is ExtendedDate) { if(destinationType == typeof(string)) return ((ExtendedDate)value).ToString(); else if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } } 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 new ExtendedDate(null); } return base.ConvertFrom (context, culture, value); } } |
#4
| |||
| |||
|
|
I know I can debug it through another instance of VS.NET. system.dll!System.ComponentModel.TypeConverter.Con vertTo(System.Object value = {TestApp.Test}, System.Type destinationType = {"System.ComponentModel.Design.Serialization.Insta nceDescriptor"}) + 0x17 bytes system.design.dll!System.ComponentModel.Design.Ser ialization.InstanceDescriptorCodeDomSerializer.Ser ialize(System.ComponentModel.Design.Serialization. IDesignerSerializationManager manager = {Microsoft.VisualStudio.Designer.Serialization.VSD esignerLoader.VsCodeDomLoader}, System.Object value = {TestApp.Test}) + 0xdb bytes system.design.dll!System.ComponentModel.Design.Ser ialization.CodeDomSerializer.SerializeToExpression It's constantly trying to serialize. This is because I have a constructor that takes the class type as parameter. (i.e.: class Test { public Test(Test t){} }) You will not be able to use this constructor with VS.NET designer and custom TypeConverter. It will go into infinite recursion trying to convert the parameter or maybe it's a limitation of designer. "Marina" <someone (AT) nospam (DOT) com> wrote in message news:uV$2z5I2EHA.2192 (AT) TK2MSFTNGP14 (DOT) phx.gbl... You can actually debug your code, and see where the overflow occurrs. Just attach one instance of the IDE with the source project for this code to an instance of the IDE trying to use your object. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OjP9mkB2EHA.2644 (AT) TK2MSFTNGP11 (DOT) phx.gbl... Hi, I get StackOverflow when I return an InstanceDescriptor which represents a constructor which takes it's own type as parameter. Could someone explain why return new InstanceDescriptor(ci,new object[]{date}); causes StackOverflow? Is it again going into the ConvertTo? Why? Short code snippet: if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } Full sample code: public class Component1 : System.ComponentModel.Component { public Component1(System.ComponentModel.IContainer container) { container.Add(this); } public Component1(){} private ExtendedDate _date; public ExtendedDate ExtendedDate { get { return _date; } set { _date = value; } } bool ShouldSerializeExtendedDate() { return true; } } [TypeConverter(typeof(ExtendedDateTypeConverter))] public class ExtendedDate { public ExtendedDate(ExtendedDate date) { } } internal sealed class ExtendedDateTypeConverter: TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value is ExtendedDate) { if(destinationType == typeof(string)) return ((ExtendedDate)value).ToString(); else if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } } 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 new ExtendedDate(null); } return base.ConvertFrom (context, culture, value); } } |
#5
| |||
| |||
|
|
I'm not sure it's necessarily the case that an object cannot take something of the same type to its constructor but at some point in the serialization, you will need to use an instancedescriptor that does not contain something of that type. With regards to your stack overflow, your initial code doesn't make sense because its passing itself into its own constructor - notice that you are passing "date" into the constructor of the InstanceDescriptor which is supposed to describe how to create "date" (i.e. the value passed into the convertto). Now if you think about it further, even if you were to pass in a different ExtendedDate object instance, that object would have to be serialized to an instance descriptor as well since .net needs to get to the point that it has serialized the value as text in the initializecomponent so at some point you would have to use a constructor that would take different parameters. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OemyV$u2EHA.2876 (AT) TK2MSFTNGP12 (DOT) phx.gbl... I know I can debug it through another instance of VS.NET. system.dll!System.ComponentModel.TypeConverter.Con vertTo(System.Object value = {TestApp.Test}, System.Type destinationType = {"System.ComponentModel.Design.Serialization.Insta nceDescriptor"}) + 0x17 bytes system.design.dll!System.ComponentModel.Design.Ser ialization.InstanceDescriptorCodeDomSerializer.Ser ialize(System.ComponentModel.Design.Serialization. IDesignerSerializationManager manager = {Microsoft.VisualStudio.Designer.Serialization.VSD esignerLoader.VsCodeDomLoader}, System.Object value = {TestApp.Test}) + 0xdb bytes system.design.dll!System.ComponentModel.Design.Ser ialization.CodeDomSerializer.SerializeToExpression It's constantly trying to serialize. This is because I have a constructor that takes the class type as parameter. (i.e.: class Test { public Test(Test t){} }) You will not be able to use this constructor with VS.NET designer and custom TypeConverter. It will go into infinite recursion trying to convert the parameter or maybe it's a limitation of designer. "Marina" <someone (AT) nospam (DOT) com> wrote in message news:uV$2z5I2EHA.2192 (AT) TK2MSFTNGP14 (DOT) phx.gbl... You can actually debug your code, and see where the overflow occurrs. Just attach one instance of the IDE with the source project for this code to an instance of the IDE trying to use your object. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OjP9mkB2EHA.2644 (AT) TK2MSFTNGP11 (DOT) phx.gbl... Hi, I get StackOverflow when I return an InstanceDescriptor which represents a constructor which takes it's own type as parameter. Could someone explain why return new InstanceDescriptor(ci,new object[]{date}); causes StackOverflow? Is it again going into the ConvertTo? Why? Short code snippet: if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } Full sample code: public class Component1 : System.ComponentModel.Component { public Component1(System.ComponentModel.IContainer container) { container.Add(this); } public Component1(){} private ExtendedDate _date; public ExtendedDate ExtendedDate { get { return _date; } set { _date = value; } } bool ShouldSerializeExtendedDate() { return true; } } [TypeConverter(typeof(ExtendedDateTypeConverter))] public class ExtendedDate { public ExtendedDate(ExtendedDate date) { } } internal sealed class ExtendedDateTypeConverter: TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value is ExtendedDate) { if(destinationType == typeof(string)) return ((ExtendedDate)value).ToString(); else if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } } 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 new ExtendedDate(null); } return base.ConvertFrom (context, culture, value); } } |
#6
| |||
| |||
|
|
I just wrote that sample specifically to repro the problem. In real case I had this: class ExtendedDate { public ExtendedDate(DatePart){} public DatePart DatePart { get { return _datePart; } } ... } class DatePart { public DatePart(DatePart){} ... } ... if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(DatePart)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date.DatePart}); } ... if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(DatePart).GetConstructor(new Type[]{typeof(DatePart)}); DatePart date = (DatePart) value; return new InstanceDescriptor(ci,new object[]{date}); } Without providing custom TypeConverter for DatePart VS designer will not serialize the ExtendedDate collection property that I exposed on my component. So i created another constructor for DatePart that takes string for parsing DatePart and now it works. But what I wanted to do is create ExtendedDate from existing ExtendedDate's DatePart directly, but that will cause StackOverFlow calling ConvertTo in recursion. "Andrew Smith (Infragistics)" <productmanager (AT) infragistics (DOT) com> wrote in message news:uaJ1dzv2EHA.1192 (AT) tk2msftngp13 (DOT) phx.gbl... I'm not sure it's necessarily the case that an object cannot take something of the same type to its constructor but at some point in the serialization, you will need to use an instancedescriptor that does not contain something of that type. With regards to your stack overflow, your initial code doesn't make sense because its passing itself into its own constructor - notice that you are passing "date" into the constructor of the InstanceDescriptor which is supposed to describe how to create "date" (i.e. the value passed into the convertto). Now if you think about it further, even if you were to pass in a different ExtendedDate object instance, that object would have to be serialized to an instance descriptor as well since .net needs to get to the point that it has serialized the value as text in the initializecomponent so at some point you would have to use a constructor that would take different parameters. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OemyV$u2EHA.2876 (AT) TK2MSFTNGP12 (DOT) phx.gbl... I know I can debug it through another instance of VS.NET. system.dll!System.ComponentModel.TypeConverter.Con vertTo(System.Object value = {TestApp.Test}, System.Type destinationType = {"System.ComponentModel.Design.Serialization.Insta nceDescriptor"}) + 0x17 bytes system.design.dll!System.ComponentModel.Design.Ser ialization.InstanceDescriptorCodeDomSerializer.Ser ialize(System.ComponentModel.Design.Serialization. IDesignerSerializationManager manager = {Microsoft.VisualStudio.Designer.Serialization.VSD esignerLoader.VsCodeDomLoader}, System.Object value = {TestApp.Test}) + 0xdb bytes system.design.dll!System.ComponentModel.Design.Ser ialization.CodeDomSerializer.SerializeToExpression It's constantly trying to serialize. This is because I have a constructor that takes the class type as parameter. (i.e.: class Test { public Test(Test t){} }) You will not be able to use this constructor with VS.NET designer and custom TypeConverter. It will go into infinite recursion trying to convert the parameter or maybe it's a limitation of designer. "Marina" <someone (AT) nospam (DOT) com> wrote in message news:uV$2z5I2EHA.2192 (AT) TK2MSFTNGP14 (DOT) phx.gbl... You can actually debug your code, and see where the overflow occurrs. Just attach one instance of the IDE with the source project for this code to an instance of the IDE trying to use your object. "LF" <lf (AT) nospam (DOT) nospam> wrote in message news:OjP9mkB2EHA.2644 (AT) TK2MSFTNGP11 (DOT) phx.gbl... Hi, I get StackOverflow when I return an InstanceDescriptor which represents a constructor which takes it's own type as parameter. Could someone explain why return new InstanceDescriptor(ci,new object[]{date}); causes StackOverflow? Is it again going into the ConvertTo? Why? Short code snippet: if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } Full sample code: public class Component1 : System.ComponentModel.Component { public Component1(System.ComponentModel.IContainer container) { container.Add(this); } public Component1(){} private ExtendedDate _date; public ExtendedDate ExtendedDate { get { return _date; } set { _date = value; } } bool ShouldSerializeExtendedDate() { return true; } } [TypeConverter(typeof(ExtendedDateTypeConverter))] public class ExtendedDate { public ExtendedDate(ExtendedDate date) { } } internal sealed class ExtendedDateTypeConverter: TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value is ExtendedDate) { if(destinationType == typeof(string)) return ((ExtendedDate)value).ToString(); else if(destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(ExtendedDate).GetConstructor(new Type[]{typeof(ExtendedDate)}); ExtendedDate date = (ExtendedDate) value; return new InstanceDescriptor(ci,new object[]{date}); } } 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 new ExtendedDate(null); } return base.ConvertFrom (context, culture, value); } } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |