开发者

Cannot access app.config or settings.settings data

开发者 https://www.devze.com 2022-12-26 01:24 出处:网络
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 retur

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

0

精彩评论

暂无评论...
验证码 换一张
取 消