开发者

Reading configuration section Failed

开发者 https://www.devze.com 2023-01-30 09:09 出处:网络
I\'m having a problem with some application. When I execute it in local disk all is ri开发者_运维技巧ght, but when I try to execute the same application from a shared resource (Z:\\resource\\TheApplic

I'm having a problem with some application. When I execute it in local disk all is ri开发者_运维技巧ght, 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.

Reading configuration section Failed

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.


You haven't declared OtherConfiguration in your class. Therefore, you cannot have it as an attribute on the DomainUserInfo in your config.

0

精彩评论

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