Quoth Windows Forms Designer: Specified Cast Is Not Valid
Let’s say you have a UserControl with a property like this:
public double DoubleValue { get { return (double)NestedControl.EditValue; } set { Control.EditValue = value; } }
where NestedControl.EditValue is of type object. Yeah, that’s careless handling of a possible typecast. But c’est la vie, sometimes that’s what you have, and you don’t know it, and that control is used in somebody else’s form that you’ve never seen before, and you are editing that form with the Windows Forms designer.

The designer will work merrily until you close it and say “yes, save for me please.” At this point it will present you with a dialog box saying simply “Specified cast is not valid” and inviting you to misrepresent your feelings by clicking “OK.”
When you do, it will give you the same dialog box again. You will click “OK” again, even less truthfully. And you will get that dialog box once again.
After the third time, tender mercies: the designer lets you off the hook and closes, saving your form. Phew, you think, maybe that wasn’t so bad. That’s until you discover that the designer has thrown out all the information associated with the problematic control instance, its name, text, tooltip text, sizing information, everything.
When you set out to find the cause of the problem, what do you have to go on? “Specified cast is not valid.” And which control instances got messed up. There may be dozens of them, with dozens of properties each. Happy hunting.
The lesson: when I write a tool for developers, and do it under a schedule crunch, and write a catch-all handler to display unanticipated errors … I pledge to include whatever specific contextual information I can. At least the exception stack trace. Surely that’s the least I could do.