Thanks Bryan, I got it. There are lists that are databinding in a
constructor and need a connection string. So I changed code to check if
time, and if so, set it to connection string on development box. At
runtime, it correctly looks to app.config. So I guess bottom line is
app.config can't be a accessed at design time. Worthy lesson!
"Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in message
news:%23Z1QJH2fHHA.4780@TK2MSFTNGP03.phx.gbl...
> Yes, that is what I am saying. Visual Studio will run the constructor and
> all properties for any component that you open in design mode.
>
> If you need to step through the code, modify your project
> properties->debugging tab to start a new instance of Visual Studio.
>
> Once the new instance of Visual Studio is open, open the project again and
> then open the form. You can set a breakpoint in the form's property in
> the first instance of Visual Studio so you can step through the code.
>
>
>
> --
> Bryan Phillips
> MCSD, MCDBA, MCSE
> Blog:
http://bphillips76.spaces.live.com > Web Site:
http://www.composablesystems.net >
>
>
> "Charlie@CBFC" <charlie@cbfconsulting.com> wrote in message
> news:#n$n9sufHHA.596@TK2MSFTNGP06.phx.gbl:
>
>> I don't understand Bryan. Are you saying that code runs when I open Form
>> for editing? So conditions might not be right at design time, but are
>> right
>> at runtime? How do you troubleshoot something like this? Doesn't make
>> sense to me to have to kludge it just so it works at design time.
>>
>> I get error "Object reference not set to an instance of an object" when I
>> open form, so it must be null. Not sure how to test it without running
>> program and stepping through code?
>>
>>
>>
>>
>> "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in
>> message
>> news:eGvPpNufHHA.1244@TK2MSFTNGP04.phx.gbl...
>> > Did you try my suggestion? Code also runs at design-time too.
>> >
>> > --
>> > Bryan Phillips
>> > MCSD, MCDBA, MCSE
>> > Blog:
http://bphillips76.spaces.live.com >> > Web Site:
http://www.composablesystems.net >> >
>> >
>> >
>> > "Charlie@CBFC" <charlie@cbfconsulting.com> wrote in message
>> > news:OtJY9AtfHHA.3632@TK2MSFTNGP02.phx.gbl:
>> >
>> >> Code compiles and runs so it's getting connection string. Problem is
>> >> this
>> >> line of code...
>> >> System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()
>> >> breaks designer. Says "Object reference not set to an instance of an
>> >> object".
>> >>
>> >>
>> >>
>> >> "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in
>> >> message
>> >> news:efDNcusfHHA.3884@TK2MSFTNGP04.phx.gbl...
>> >> > Change your code to test if
>> >> > System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"]
>> >> > is null before calling ToString().
>> >> >
>> >> > Ex:
>> >> >
>> >> > public static string _connectionString = String.Empty;
>> >> > public static string ConnectionString {
>> >> > get {
>> >> > if( _connectionString == String.Empty ) {
>> >> > if
>> >> > (System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"]
>> >> > != null) {
>> >> > _connectionString =
>> >> > System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
>> >> > }
>> >> > }
>> >> > return _connectionString;
>> >> > }
>> >> > }
>> >> >
>> >> > --
>> >> > Bryan Phillips
>> >> > MCSD, MCDBA, MCSE
>> >> > Blog:
http://bphillips76.spaces.live.com >> >> > Web Site:
http://www.composablesystems.net >> >> >
>> >> >
>> >> >
>> >> > "Charlie@CBFC" <charlie@cbfconsulting.com> wrote in message
>> >> > news:OYB$TYqfHHA.4064@TK2MSFTNGP03.phx.gbl:
>> >> >
>> >> >> Hi:
>> >> >>
>> >> >> This code compiles and runs fine, but I get this error when try to
>> >> >> open a
>> >> >> form in WinForm designer. Commenting it out fixes problem. Weird!
>> >> >>
>> >> >> "Object reference not set to an instance of an object.
>> >> >> at RepairShop.DataService.get_ConnectionString() in C:\My
>> >> >> Projects\RepairShop\DataService.cs:line 16"
>> >> >>
>> >> >>
>> >> >> public static string _connectionString = String.Empty;
>> >> >> public static string ConnectionString {
>> >> >> get {
>> >> >> if( _connectionString == String.Empty ) {
>> >> >> _connectionString =
>> >> >> System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
>> >> >> }
>> >> >> return _connectionString;
>> >> >> }
>> >> >> }
>> >> >>
>> >> >> Thanks!
>> >> >> Charlie
>> >> >
>> >
>