0

我有一个需要从 settings.settings 或 app.config 加载字符串的 .Net 3.5 应用程序。我确定我有一个对 ConfigurationManager 的引用,但是来自表单加载值的一个非常简单的调用返回 null。

这是代码:

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.
}
4

1 回答 1

0

如果您正在使用设置设计器,并且您的项目在项目根目录的 Proepties 节点下有 Settings.settings/Settings.Designer.cs,那么您根本不会在设置中获得这样的值,您会得到它们:

m_connStr = YOUR_PROJECT_NAMESPACE.Properties.Settings.Default.YOUR_SETTING_NAME

设置设计器可能会在内部使用 System.Configuration 命名空间,但您永远不会这样做

于 2013-10-02T09:01:58.323 回答