It always pisses me off when VS sets custom properties of UserControl to null, at design time. Properties that should not be null, that in turn breaks design view of my Custom Controls. It you do not put any assertions on property set, you’ll get all-informative „Null reference exception”.
Now go get your magic crystal ball and find where the heck VS broke the code, cause this very helpful stack trace have no value:
Object reference not set to an instance of an object. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
I do two things:
- Always put null assertions on not null property set, so I will know at least property or variable name when an exception is thrown.
- Add attributes to UserControl custom properties so VS will not touch them:
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Pingback: It should just work! » Blog Archive » Value Exception info as it was Gold