简体   繁体   中英

Designer can't read config file

I have a WPF application and the designer shows a lot of error messages but the actual program works fine.

The core of the problem seems to be the inability of the designer to find a connection string in the config

InvalidOperationException: No connection string named 'HeliDataDBEntities' could be found in the application config file.

The config contains

  <connectionStrings>
      <add name="HeliDataDBEntities" connectionString="metadata=res://*/Database.csdl|res://*/Database.ssdl|res://*/Database.msl;provider=System.Data.SqlClient;provider connection string=...;" providerName="System.Data.EntityClient" />
  </connectionStrings>

While it's not affecting the actual code, losing the WYSIWYG element of the designer is annoying, and having the error list full of errors that aren't affecting code compilation is making it harder to spot any real errors.

Is there a reason that the designer can't find this?

Yes. Config files are relative to the application starting. Guess what the application is for the designer - visual studio.

You break best practices. The designer should not connect to the database at all (under pretty much no circumstances) and work with fake data.

Check via

DesignerProperties.GetIsInDesignMode(this);

Whether you are in design mode - if you are, do not even try accessing the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM