By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,222 Members | 1,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,222 IT Pros & Developers. It's quick & easy.

Using ConfigurationManager breaks WinForms designer...

P: n/a
Hi:

Program runs and compiles fine, but WinForms designer breaks when using this
line of code...

ConfigurationManager.ConnectionStrings["RepairShop.Properties.Settings.BaseRepairShopConn ectionString"].ToString();

It says "Object reference not set to an instance of an object". How then do
I access app.config?

Thanks,
Charlie
Apr 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Charlie,

Can you do this somewhere else other than the constructor of your code?
It's not that the WinForms designer is broken, but rather, you don't have
access to the app config file at that time when the designer is trying to
render your form. An exception gets thrown in the constructor, and the
designer doesn't know what to do.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charlie@CBFC" <ch*****@cbfconsulting.comwrote in message
news:%2*****************@TK2MSFTNGP05.phx.gbl...
Hi:

Program runs and compiles fine, but WinForms designer breaks when using
this line of code...

ConfigurationManager.ConnectionStrings["RepairShop.Properties.Settings.BaseRepairShopConn ectionString"].ToString();

It says "Object reference not set to an instance of an object". How then
do I access app.config?

Thanks,
Charlie

Apr 14 '07 #2

P: n/a
Hi Nicholas:

I'm not using it a constructor. I'm using it in a property like so...

public static string _connectionString = String.Empty;
public static string ConnectionString {
get {
if( _connectionString == String.Empty ) {
_connectionString =
ConfigurationManager.ConnectionStrings["RepairShop.Properties.Settings.BaseRepairShopConn ectionString"].ToString();
}
return _connectionString;
}
}

I've tried it in other places without success. I'm at my wits end.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uo*************@TK2MSFTNGP03.phx.gbl...
Charlie,

Can you do this somewhere else other than the constructor of your code?
It's not that the WinForms designer is broken, but rather, you don't have
access to the app config file at that time when the designer is trying to
render your form. An exception gets thrown in the constructor, and the
designer doesn't know what to do.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charlie@CBFC" <ch*****@cbfconsulting.comwrote in message
news:%2*****************@TK2MSFTNGP05.phx.gbl...
>Hi:

Program runs and compiles fine, but WinForms designer breaks when using
this line of code...

ConfigurationManager.ConnectionStrings["RepairShop.Properties.Settings.BaseRepairShopConn ectionString"].ToString();

It says "Object reference not set to an instance of an object". How then
do I access app.config?

Thanks,
Charlie


Apr 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.