all groups > dotnet windows forms designtime > october 2004 >
You're in the

dotnet windows forms designtime

group:

Constructors/Initializers/ConfigurationSettings in design time...



Constructors/Initializers/ConfigurationSettings in design time... Mike Edenfield
10/26/2004 1:45:26 PM
dotnet windows forms designtime: I have a series of user controls which internally contain datasets. At
run-time, these datasets are loaded from XML documents in the following
manner:

private string _xmlPath = ConfigurationSettings.AppSettings["XML.Path"];

public UserControl1()
{
InitializeComponent();
this._xmlPath = ConfigurationSettings.AppSettings["XML.Path"];
string s = Path.Combine(this._xmlPath, "Doc1.xml");
this.UserControlData.ReadXml(fileName);
}

The problem is that "this._xmlPath" is never properly initialized at
design-time. I always encounter "Value cannot be null. Parameter:
path1" errors on the Path.Combine function call.

I don't actually need this data at design-time, so I could just not let
this code run in the designers. But I can't figure out how to tell when
a control is being designed or is being run. Ideally it should just
work as is, but I cannot get the configuration settings to properly load
at design-time. (I have an app.config in my project and it has been
subsequently built into an EXENAME.config file in the Debug folder...)

Any ideas?

--Mike

Re: Constructors/Initializers/ConfigurationSettings in design time... joeycalisay
10/27/2004 1:02:44 PM
[quoted text, click to view]

perhaps the retrieval of data for the UserControl should be on the OnLoad
event of the UserControl. At that event, you can test if the control is
being loaded at runtime or designtime using its DesignMode property and
execute your data retrieval statements if it is not at DesignMode (meaning
runtime).

[quoted text, click to view]

app.config file becomes application.exe.config when build, i believe it's by
default. I have no idea about loading from configuration file which is part
of the project at designtime.

AddThis Social Bookmark Button