Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. .net 2.0 Custom Configuration Sections

.net 2.0 Custom Configuration Sections

Scheduled Pinned Locked Moved C#
csharphelpvisual-studiodebuggingworkspace
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndieDu
    wrote on last edited by
    #1

    Dear All, I am trying to create a class to handle my custom config sections in my app.config file, but no matter what i tried, i always get this kind of error: Unrecognized attribute 'name'. Note that attribute names are case-sensitive. (D:\Users\xxx\Documents\Visual Studio 2005\Projects\ConsoleApplication2\ConsoleApplication2\bin\Debug\ConsoleApplication2.vshost.exe.config line 10) I had spent about half days to try to fix this annoy error but without any luck. can someone in here shed me a light will be greatly appreciated. This is my app.config file: and this is my source code: using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace ConsoleApplication2 { public class Class1: ConfigurationSection { [ConfigurationProperty("package")] public PackageVersionCollection PackageVersionItems { get { return ((PackageVersionCollection)(base["package"])); } } } [ConfigurationCollection(typeof(PackageVersionElement))] public class PackageVersionCollection : ConfigurationElementCollection { protected override ConfigurationElement CreateNewElement() { return new PackageVersionElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((PackageVersionElement)(element)).Name; } public PackageVersionElement this[int idx] { get { return (PackageVersionElement)BaseGet(idx); } } } public class PackageVersionElement : ConfigurationElement { [ConfigurationProperty("name", DefaultValue = "", IsKey = true, IsRequired = true)] pu

    K 1 Reply Last reply
    0
    • A AndieDu

      Dear All, I am trying to create a class to handle my custom config sections in my app.config file, but no matter what i tried, i always get this kind of error: Unrecognized attribute 'name'. Note that attribute names are case-sensitive. (D:\Users\xxx\Documents\Visual Studio 2005\Projects\ConsoleApplication2\ConsoleApplication2\bin\Debug\ConsoleApplication2.vshost.exe.config line 10) I had spent about half days to try to fix this annoy error but without any luck. can someone in here shed me a light will be greatly appreciated. This is my app.config file: and this is my source code: using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace ConsoleApplication2 { public class Class1: ConfigurationSection { [ConfigurationProperty("package")] public PackageVersionCollection PackageVersionItems { get { return ((PackageVersionCollection)(base["package"])); } } } [ConfigurationCollection(typeof(PackageVersionElement))] public class PackageVersionCollection : ConfigurationElementCollection { protected override ConfigurationElement CreateNewElement() { return new PackageVersionElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((PackageVersionElement)(element)).Name; } public PackageVersionElement this[int idx] { get { return (PackageVersionElement)BaseGet(idx); } } } public class PackageVersionElement : ConfigurationElement { [ConfigurationProperty("name", DefaultValue = "", IsKey = true, IsRequired = true)] pu

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      It is hard to read your code, can you tag it up please. AFAICT, This is what defines the element package

      [ConfigurationProperty("package")]
      public PackageVersionCollection PackageVersionItems
      {
      get
      {
      return ((PackageVersionCollection)(base["package"]));
      }
      }

      It should contain a sub-element containing a list of PackageVersionItems. But your config does something different:

      <packageVersionSection>
      <packageVersion>
      <package name="Web Application" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWebApps" />....

      The package is an element in the collection. You also define a "name" property here this isn't in the class I've copied. As a rule of thumb, you should make sure your class names always tally up with the property names you intend them for. [edit] fixed the XML markup so it would actually display, haven't done that in a while :-O

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]

      A 1 Reply Last reply
      0
      • K Keith Barrow

        It is hard to read your code, can you tag it up please. AFAICT, This is what defines the element package

        [ConfigurationProperty("package")]
        public PackageVersionCollection PackageVersionItems
        {
        get
        {
        return ((PackageVersionCollection)(base["package"]));
        }
        }

        It should contain a sub-element containing a list of PackageVersionItems. But your config does something different:

        <packageVersionSection>
        <packageVersion>
        <package name="Web Application" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWebApps" />....

        The package is an element in the collection. You also define a "name" property here this isn't in the class I've copied. As a rule of thumb, you should make sure your class names always tally up with the property names you intend them for. [edit] fixed the XML markup so it would actually display, haven't done that in a while :-O

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]

        A Offline
        A Offline
        AndieDu
        wrote on last edited by
        #3

        It is the issue with my bloody xml file, it should be like this:

        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
        <configSections>
        <sectionGroup name="packageVersionSection">
        <section name="packageVersion" type="ConsoleApplication2.Class1, ConsoleApplication2" />
        </sectionGroup>
        </configSections>
        <packageVersionSection>
        <packageVersion>
        <packages>
        <add name="Web Application" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWebApps" />
        <add name="RPU Applications" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWinApps" />
        <add name="Shared Applications" version="1.1.2.0" location="C:\Program Files\TeleMedCare\SharedApp" />
        </packages>
        </packageVersion>
        </packageVersionSection>
        </configuration>

        I just missed the 'packages' element in my previous posting and i should use 'add'. Thanks a lot for ur help anyway.

        K 1 Reply Last reply
        0
        • A AndieDu

          It is the issue with my bloody xml file, it should be like this:

          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
          <configSections>
          <sectionGroup name="packageVersionSection">
          <section name="packageVersion" type="ConsoleApplication2.Class1, ConsoleApplication2" />
          </sectionGroup>
          </configSections>
          <packageVersionSection>
          <packageVersion>
          <packages>
          <add name="Web Application" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWebApps" />
          <add name="RPU Applications" version="1.1.2.1" location="C:\Program Files\TeleMedCare\TMSWinApps" />
          <add name="Shared Applications" version="1.1.2.0" location="C:\Program Files\TeleMedCare\SharedApp" />
          </packages>
          </packageVersion>
          </packageVersionSection>
          </configuration>

          I just missed the 'packages' element in my previous posting and i should use 'add'. Thanks a lot for ur help anyway.

          K Offline
          K Offline
          Keith Barrow
          wrote on last edited by
          #4

          Easily done, at least it's fixed!

          Sort of a cross between Lawrence of Arabia and Dilbert.[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups