WPF Designer ONLY: NullReferenceException when loading connection string from app.config -


Please help for my non-pulled hair ...

The following code line:

  this._connectionString = ConfigurationManager.ConnectionStrings ["SqlConnectionString"]. connection string;  

I am generating sorrow in countless quantities

This is a user under control, currently in the loaded event of control, but I have tried the constructor And when the field has been declared, then that field is started only in the initial form. Whenever I do this, the WPF Designer fits on any screen that uses User Control.

The code itself compile itself, and there is no problem. But it is changing into a real obstacle in the development, which is not able to use the designer at all. Does anyone have any clue which can indicate this in the form of some good practice to avoid it in the future? I suspect that there is something to try to use this configuration manager, but I did not know where to stop it.

Thank you.

Re-Visual Studio 2010 Premium

When you are working in design time , You should refrain from loading it. Fill the price with another, instead of the appropriate default:

  if (DesignerProperties.GetIsInDesignMode (this)) this._connectionString = "Default"; Else {this._connectionString = Configuration Manager. Connection connection ["SqlConnectionString"]. Connection String; }  

Comments