我有一个.Net 3.5应用程序需要从settings.settings或app.config加载一个字符串。我确保我有一个对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.
}
答案 0 :(得分:0)
如果您正在使用设置设计器,并且您的项目在项目根目录的Proepties节点下具有Settings.settings / Settings.Designer.cs,那么您根本不会在设置中获取值,让他们像:
m_connStr = YOUR_PROJECT_NAMESPACE.Properties.Settings.Default.YOUR_SETTING_NAME
设置设计器可能会在内部使用System.Configuration命名空间,但您永远不会使用