【发布时间】:2012-03-06 21:13:14
【问题描述】:
在 web.config 文件中,我有一个 3rd 方设置部分:
<configuration>
<configSections>
<sectionGroup name="TheProduct">
<section name="TheSection" type="TheCompany.TheProduct.TheSectionConfigurationHandler, TheCompany.TheProduct, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1e9bee111e9429c" />
</sectionGroup>
</configSections>
<TheProduct>
<TheSection somevalue="true" />
</TheProduct>
</configuration>
我想从另一个应用程序读取此部分的值,但是当我尝试查找该部分时,我总是得到null。
这是我的代码:
var config = ConfigurationManager.OpenExeConfiguration(
@"C:\inetpub\wwwroot\TheProduct\web.config"
);
var settings = config.GetSection("TheProduct/TheSection"); // always null
检索配置部分的正确方法是什么?
[编辑]如果调用应用程序,它定义了相同的部分,我可以这样做:
var settings = ConfigurationManager.GetSection("TheProduct/TheSection");
它正在工作。 Mybe 我没有使用正确的方式打开 web.config 文件?
【问题讨论】:
-
您的应用程序中是否引用了
TheCompany.TheProduct, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1e9bee111e9429c? -
不...实际上节处理程序在 3rd 方库中是内部的。我想使用反射来读取值。
-
编辑:我有对第 3 方库的引用...我只是无法自己实例化类型
-
希望对您有所帮助,stackoverflow.com/questions/9826744/…>
标签: c# configuration