473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Using ConfigurationManager breaks WinForms designer...

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
2 4327
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work...
4
by: Charles Fineblum | last post by:
Hi: I'm getting subject error when loading Form into WinForms designer. Application complies and runs fine, but can not load form into designer. This has happened twice and forced me to restart...
4
by: Elhanan | last post by:
hi.. all a client of ours is considering to move from a dos application to windows desktop application. the application is for traveling agency, the database is rather large. their current...
4
by: rmacias | last post by:
I posted this in another forum, but nobody replied and I need an answer fairly quickly: I'm creating a Windows form application in VC++ .NET 2003. I'm creating the UI is a nested namespace as...
0
by: rmacias | last post by:
I posted this in another forum but nobody has answered it: I'm creating a Windows form application in VC++ .NET 2003. I'm creating the UI is a nested namespace as follows: namespace...
0
by: rmacias | last post by:
I'm creating a Windows form application in VC++ .NET 2003. I'm creating the UI is a nested namespace as follows: namespace MyApplication { namespace GUI { //form class goes here } }
1
by: Chung | last post by:
Hi I am trying to create a Web applicatiion by using windows user control. I am having problem when I trying to load the web page, I got blank screen with a broken image. It is like the web...
2
by: Peted | last post by:
Can anyone suggest a best practice approach to building a dynamic winforms UI. Just as an example somehting like a billing application where you enter a customer billing data and the billing...
23
by: raylopez99 | last post by:
Here I am learning WinForms and two months into it I learn there's a WPF API that is coming out. Is this WPF out yet, and is it a threat to WinForms, in the sense that all the library routines I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.