Some of my forms show errors when i load them in the designer. This is because in their constructors they use system settings loaded from a configuration file. When the form is loaded in the designer it uses some random path and unsurprisingly the config file isn't there.
eg. The configuration file C:\Documents and Settings\Rory\Local Settings\Application Data\Microsoft\VisualStudio\8.0\ProjectAssemblies\it3dtcgg01\PrioryShared.dll.config could not be found.
Is there some way I can deal with this so that the form displays correctly in the designer? eg:
if (!inDesignerMode)
{
loadSettingsFromConfigFile();
}
UPDATE: ok, I'm still getting this error. The composition is like this
MyForm.cs
- MyCustomControl.cs
In MyCustomControl's constructor I've put
if (!this.DesignMode)
{
// Get settings from config file <- this is where the error occurs
}
but it's on that line that I still get the error in the designer. What gives?
UPDATE: Worth noting this link that describes how to debug design-time controls.
UPDATE: Control.DesignMode isn't set to true when called within the constructor (MSDN) of the object! So that sort of code should go in the onLoad. Alternatively you can use an approach like this