views:

64

answers:

1

Hello,

I have a form that will not open in the designer. I used the technique that I mention in an answer to THIS questions...

http://stackoverflow.com/questions/513798/visual-studio-winforms-designer-does-not-instantiate-object/947009#947009

...to determine why the form will not open in the designer.

The bottom line is that the form's load event tries to load some custom business objects which gets data from a database. The line that is failing is ...

Dim connStr As String = ConfigurationManager.ConnectionStrings(connectionStringName).ConnectionString

...this returns a null reference exception. It cannot find my named connectionstring in the calling context of opening the form in the designer while not in design mode.

Why is this? The connectionstring is in the app.config of the project that the form is in. All I can think of is that the Designer is opening in it's own context and does not use the app.config of the winforms project. In fact, in the break context...the configuration manager IS holding two connectionstrings...neither of which is in my projects app.config. They are as follows...

?configurationmanager.ConnectionStrings(0).ConnectionString "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

and

?configurationmanager.ConnectionStrings(1).ConnectionString "data source="|DataDirectory|\aspnetdb.vdb3""

...I mention those as possible clues. Neither of these connectstring are mine. But they do each references two db providers that I want to support in my project...sql and vistadb.

All of that to say...is there a way of determining the run context being used by the designer so that I can add data to an app.config so that it will not break on this error. Or (better) is there a way to force the designer to use my custom app.config. Where is the app.config being used by the designer located?

Thanks for your help in advance.

Seth

+1  A: 

Wrap the code that breaks the designer in the Load event in the following:

if ( this.Site == null || !this.Site.DesignMode )
{
... // code that breaks the designer
}
Arnshea
Thanks...that did it...except I did it in VB.Seth
Seth Spearman