I have a .Net 3.5 application that needs to load a string from settings.settings or app.config. I made sure I have a reference to ConfigurationManager but a very simple call from form load value returns null.
Here is the code:
void LoadSettings()
{
// I expect to get from my app.config or settings.settings
// Settings file set to application, public
m_connStr = System.Configuration.ConfigurationManager.AppSettings["somestring"];
/开发者_运维百科/ m_connStr is getting Null. I tried .ToString(); That throws a null exception.
}
If you're using the settings designer, and your project has Settings.settings/Settings.Designer.cs under the Proepties node of the project root, then you don't get values in your settings like that at all, you get them like:
m_connStr = YOUR_PROJECT_NAMESPACE.Properties.Settings.Default.YOUR_SETTING_NAME
Settings designer might use the System.Configuration namespace internally, but you never do
精彩评论