Re: This code compiles/runs but breaks designer...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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@xxxxxxxxxxxxxxxxx> wrote in message news:#n$n9sufHHA.596@xxxxxxxxxxxxxxxxxxxx:

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@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eGvPpNufHHA.1244@xxxxxxxxxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxxxx> wrote in message
> news:OtJY9AtfHHA.3632@xxxxxxxxxxxxxxxxxxxx:
>
>> 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@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
>> message
>> news:efDNcusfHHA.3884@xxxxxxxxxxxxxxxxxxxxxxx
>> > 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@xxxxxxxxxxxxxxxxx> wrote in message
>> > news:OYB$TYqfHHA.4064@xxxxxxxxxxxxxxxxxxxx:
>> >
>> >> 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
>> >
>

.



Relevant Pages

  • Re: ASP.NET
    ... The thing to keep in mind is that Visual Studio is more a development ... FrontPage should be enhanced to integrate better with the Visual Studio ... since its strength is page design. ... >> o WYSIWYG design tools like FrontPage and Dreamweaver don't ...
    (microsoft.public.frontpage.client)
  • Re: Object events
    ... > protected override void OnInit ... > C:\Program Files\Microsoft Visual Studio ... I don't use design view at all. ... >> If you change language to VB.NET that you can see events also in code ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Visual Studio 2010 Concept IDE
    ... They actually use design ideas that ... > Visual Studio 2010 Concept IDE ... > "Like a concept car strutting its stuff, the Visual Studio 2010 Concept ... this UI designed for one thing: jamming out code. ...
    (microsoft.public.dotnet.general)
  • Re: Extermely nasty bug with the way .NET handles references
    ... using Visual Studio to design an application using a solution that ... inherited base components are in the same project as the components ... I have used the Assembly Binding Log Viewer to look for the binding ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple user control
    ... Object reference not set to an instance of an object. ... In my design view it looks like this: ... > protected UCFilter UCFilter1; ... I want to access the exposed property ...
    (microsoft.public.dotnet.framework.aspnet)