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 failedThe 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.EditLink 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. 这篇关于读取配置部分失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 02:36