读取配置部分失败 [英] Reading configuration section Failed
问题描述
我对某些应用程序有疑问.当我在本地磁盘上执行它时,一切正常,但是当我尝试从共享资源(Z:\ resource \ TheApplication.exe)执行相同的应用程序时,出现以下错误:
Error occurred creating the configuration section handler for DOMAIN/DomainUserInfo: Request failed
尝试读取配置文件中的自定义部分时发生错误:
public static class AppConfigFile {
public static IDomainUserInfo DomainUserInfo {
get {
if (_domainUserInfo == null) {
_domainUserInfo = (DomainUserInfo)ConfigurationManager.GetSection(Environment.UserDomainName + @"/DomainUserInfo");
} return _domainUserInfo as IDomainUserInfo;
}
}
}
public class DomainUserInfo : ConfigurationSection, IDomainUserInfo {
[ConfigurationProperty("SomeConfiguration", IsRequired = true, DefaultValue = "")]
public string SomeConfiguration { get { return (string)base["SomeConfiguration"]; } }
[ConfigurationProperty("OtherConfiguration", IsRequired = true, DefaultValue = "")]
public string OtherConfiguration { get { return (string)base["OtherConfiguration"]; } }
}
配置文件如下:
<configuration>
<configSections>
<sectionGroup name="THE_DOMAIN" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DomainUserInfo" type="NameSpace.Other.DomainUserInfo,NameSpace.Other" requirePermission="false"/>
</sectionGroup>
</configSections>
<THE_DOMAIN>
<DomainUserInfo SomeConfiguration="SomeValue" OtherConfiguration="OtherValue"></DomainUserInfo>
</THE_DOMAIN>
</configuration>
有什么想法吗?
谢谢.
您描述的问题是由错误.
编辑
由于重新设计了 Microsoft Connect ,自Visual Studio 2012发行以来,错误的链接不再可用.一个>网站.我再也找不到新的 Microsoft Connect 上的缺陷,也不记得它的编号了.
我唯一能找到的就是那个错误的链接仍然保留在 Google 的缓存中.
作为解决方法,它帮助我打开了使用代码的 Application Configuration :
configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
,然后使用以下代码阅读自定义部分:
CustomSection1 customSection1 = (CustomSection1)configuration.GetSection("CustomSection1");
注意::我在答案中找到了解决类似问题的方法.>
I'm having a problem with some application. When I execute it in local disk all is right, but when I try to execute the same application from a shared resource (Z:\resource\TheApplication.exe) I got the following error:
Error occurred creating the configuration section handler for DOMAIN/DomainUserInfo: Request failed
The error occurs when trying to read a custom section in the configuration file:
public static class AppConfigFile {
public static IDomainUserInfo DomainUserInfo {
get {
if (_domainUserInfo == null) {
_domainUserInfo = (DomainUserInfo)ConfigurationManager.GetSection(Environment.UserDomainName + @"/DomainUserInfo");
} return _domainUserInfo as IDomainUserInfo;
}
}
}
public class DomainUserInfo : ConfigurationSection, IDomainUserInfo {
[ConfigurationProperty("SomeConfiguration", IsRequired = true, DefaultValue = "")]
public string SomeConfiguration { get { return (string)base["SomeConfiguration"]; } }
[ConfigurationProperty("OtherConfiguration", IsRequired = true, DefaultValue = "")]
public string OtherConfiguration { get { return (string)base["OtherConfiguration"]; } }
}
The configuration file looks like:
<configuration>
<configSections>
<sectionGroup name="THE_DOMAIN" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DomainUserInfo" type="NameSpace.Other.DomainUserInfo,NameSpace.Other" requirePermission="false"/>
</sectionGroup>
</configSections>
<THE_DOMAIN>
<DomainUserInfo SomeConfiguration="SomeValue" OtherConfiguration="OtherValue"></DomainUserInfo>
</THE_DOMAIN>
</configuration>
Any ideas?
Thanks.
The problem you have described is caused by a bug in application configuration functionality of .NET 4.0.
Edit
Link to bug is not available anymore approximately since release of Visual Studio 2012 due to re-design of Microsoft Connect website. I did not manage to find defect on new Microsoft Connect anymore and do not remember its number.
The only thing I have managed to find is that link to that bug still remains in Google's cache.
As a work around it helped for me to open Application Configuration with code:
configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
and then read custom section with following code:
CustomSection1 customSection1 = (CustomSection1)configuration.GetSection("CustomSection1");
Note : Work around was found by me in answer to similar question.
这篇关于读取配置部分失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!