System.Configuration.ConfigurationErrorsException - Unrecognized element 'setting'

13,509

I found the problem. In my config I had this:

  <AppInfo>
    <AutoPay.Common.Credentials>
      <setting name="UserName" serializeAs="String"><value>********</value></setting>
      <setting name="Password" serializeAs="String"><value>********</value></setting>
      <setting name="ServiceUrl" serializeAs="String"><value>********</value></setting>
    </AutoPay.Common.Credentials>
  </AppInfo>

I changed it to:

  <AppInfo>
    <AutoPay.Common.Credentials>
      <setting name="UserName" serializeAs="String">
        <value>********</value>
      </setting>
      <setting name="Password" serializeAs="String">
        <value>********</value>
      </setting>
      <setting name="ServiceUrl" serializeAs="String">
        <value>********</value>
      </setting>
    </AutoPay.Common.Credentials>
  </AppInfo>

Don't ask me why the underlying xml reader cannot differentiate between the two. However, problem solved! grrrr...

Share:
13,509

Related videos on Youtube

Keith Barrows
Author by

Keith Barrows

Keith lives in Florida and specializes in Information Technology applications utilizing web technologies. He has been working in software ever since high school and stepped forward as a professional in the early 1990s. He is very good at figuring out new things on the fly. Technology is always changing. What is hot today is a memory tomorrow. Realizing this early on he spent his time becoming a Self-Sufficient Developer, somebody who can learn new things as they arise. He has demonstrated a passion to be highly proficient in any project he tackles. With over 20 years of experience Keith has consulted on all aspects of the software development life cycle from design and development to quality assurance and maintenance. He has worked in both the Agile and Water Fall methodologies of software creation, to include Scrum, Kan-ban and XP. Keith has a broad set of skills in the web sphere from light UI design to a deeper server-side knowledge of .NET including Core, Entity Framework, Web Forms, MVC, Web API, C#, VB as well as T-SQL and NoSql. Some of Keith's highlights include: Designed and built a Web Forms based system to replace a highly manual and error prone process that ended up saving the client over $10 million in governmental fines. Worked on updating a legacy system that could no longer handle the client load allowing the system to go from 100 clients with 100 users each to 500 clients with 250 users each. Experience leading 3 to 10 member development teams. Volunteered to be part of a 4 man team to self lead the development teams consisting of 26 developers and 8 QA personnel as the company was missing a CTO. Currently, Keith is an independent consultant with 20+ years of industry experience actively pursuing an even deeper understanding of .NET, cloud based security and web development. He is active on Stack Overflow, was a former ASP.NET MVP and a founding member of the ASPInsiders.

Updated on June 18, 2022

Comments

  • Keith Barrows
    Keith Barrows almost 2 years

    Unrecognized element 'setting'. (C:\Dev\DOT.NET\AutoPay\ibeam.config line 15)

    AppInfo.Sections.Get("AutoPay.Common.Credentials") 'AppInfo.Sections.Get("AutoPay.Common.Credentials")' threw an exception of type 'System.Configuration.ConfigurationErrorsException' System.Configuration.ConfigurationSection {System.Configuration.ConfigurationErrorsException}

    My config file:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
    <sectionGroup name="AppInfo" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="AutoPay.Common.Credentials" 
               type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                   allowExeDefinition="MachineToLocalUser" 
                   requirePermission="false" />
        </sectionGroup>
      </configSections>
    
      <AppInfo>
        <AutoPay.Common.Credentials>
          <setting name="UserName" serializeAs="String"><value>********</value></setting>
          <setting name="Password" serializeAs="String"><value>********</value></setting>
          <setting name="ServiceUrl" serializeAs="String"><value>********</value></setting>
        </AutoPay.Common.Credentials>
      </AppInfo>
    </configuration>
    

    Base (abstract) class:

    public abstract class BaseConfigInfo : ConfigurationSectionGroup
    {
        protected Configuration Configuration;
        protected ConfigurationSectionGroup AppInfo;
        protected ClientSettingsSection Credentials;
    
        protected BaseConfigInfo(string configFile)
        {
            var fileMap = new ConfigurationFileMap(configFile);
            Configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            AppInfo = Configuration.GetSectionGroup("AppInfo");
    
            // THIS IS WHERE THE ERROR POPS //
            Credentials = (ClientSettingsSection)AppInfo.Sections.Get("AutoPay.Common.Credentials");
        }
    
        protected string GetCredentialsString(string kvpName)
        {
            var setting = Credentials.Settings.Get(kvpName);
            return setting.Value.ValueXml.InnerText;
        }
    
        public string UserName { get { return GetCredentialsString("UserName"); } }
        public string Password { get { return GetCredentialsString("Password"); } }
        public string ServiceUrl { get { return GetCredentialsString("ServiceUrl"); } }
    }
    

    Sample concrete class:

    public class ConfigInfoIbeam : BaseConfigInfo
    {
        public ConfigInfoIbeam() : base(ConfigurationManager.AppSettings["ConfigInfoIbeam"]) { }
    }
    

    I know I am missing something simple here. I'm running in .NET 4. Nothing too usefull showing up when I try to google for this error. Any ideas?

  • Greg Oks
    Greg Oks over 8 years
    yeah you can also see the explanation here: blogs.msdn.microsoft.com/tess/2010/02/16/… , dont see much sense why this happens..