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. Custom config sections problem.

Custom config sections problem.

Scheduled Pinned Locked Moved C#
helpcomxmlquestionannouncement
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.
  • Z Offline
    Z Offline
    Zeokat
    wrote on last edited by
    #1

    This problem is giving me a lot of headaches and can´t find the solution... I´m reading this article Custom Configuration Sections for Lazy Coders[^] I´m reading the part titled "The Hello, World ConfigurationSection" , using exactly same code (copy paste directly) and always obtain an error when execute the program (it not returns error/warnings on compiling time). The error says that can´t load config.SomeSettings from asembly... My app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="config.SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration> Proyect --> properties , shows me that the name of my assembly is "config" I´m totally lost, found more codes similar to the one explained into this article and always, ALWAYS, always obtain the same error.... perhaps someone can give me a hand, thanks :)

    S 1 Reply Last reply
    0
    • Z Zeokat

      This problem is giving me a lot of headaches and can´t find the solution... I´m reading this article Custom Configuration Sections for Lazy Coders[^] I´m reading the part titled "The Hello, World ConfigurationSection" , using exactly same code (copy paste directly) and always obtain an error when execute the program (it not returns error/warnings on compiling time). The error says that can´t load config.SomeSettings from asembly... My app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="config.SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration> Proyect --> properties , shows me that the name of my assembly is "config" I´m totally lost, found more codes similar to the one explained into this article and always, ALWAYS, always obtain the same error.... perhaps someone can give me a hand, thanks :)

      S Offline
      S Offline
      Sk93
      wrote on last edited by
      #2

      Just a quick check, but your namespace that the class sits in is definately config right? Eg, the code should look something like this:

      using System;
      using System.Configuration;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;

      namespace config
      {
      public class SomeSettings : ConfigurationSection
      {
      private SomeSettings() { }

          \[ConfigurationProperty("FillColor", DefaultValue = "Cyan")\]
          public System.Drawing.Color FillColor
          {
              get { return (System.Drawing.Color)this\["FillColor"\]; }
              set { this\["FillColor"\] = value; }
          }
      
          \[ConfigurationProperty("TextSize", DefaultValue = "8.5")\]
          public float TextSize
          {
              get { return (float)this\["TextSize"\]; }
              set { this\["TextSize"\] = value; }
          }
      
          \[ConfigurationProperty("FillOpacity", DefaultValue = "40")\]
          public byte FillOpacity
          {
              get { return (byte)this\["FillOpacity"\]; }
              set { this\["FillOpacity"\] = value; }
          }
      }
      

      }

      Z 1 Reply Last reply
      0
      • S Sk93

        Just a quick check, but your namespace that the class sits in is definately config right? Eg, the code should look something like this:

        using System;
        using System.Configuration;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;

        namespace config
        {
        public class SomeSettings : ConfigurationSection
        {
        private SomeSettings() { }

            \[ConfigurationProperty("FillColor", DefaultValue = "Cyan")\]
            public System.Drawing.Color FillColor
            {
                get { return (System.Drawing.Color)this\["FillColor"\]; }
                set { this\["FillColor"\] = value; }
            }
        
            \[ConfigurationProperty("TextSize", DefaultValue = "8.5")\]
            public float TextSize
            {
                get { return (float)this\["TextSize"\]; }
                set { this\["TextSize"\] = value; }
            }
        
            \[ConfigurationProperty("FillOpacity", DefaultValue = "40")\]
            public byte FillOpacity
            {
                get { return (byte)this\["FillOpacity"\]; }
                set { this\["FillOpacity"\] = value; }
            }
        }
        

        }

        Z Offline
        Z Offline
        Zeokat
        wrote on last edited by
        #3

        I solved it definetly... i not defined any namespace, so the problem was in App.config... <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration> And all works good :)

        S 1 Reply Last reply
        0
        • Z Zeokat

          I solved it definetly... i not defined any namespace, so the problem was in App.config... <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration> And all works good :)

          S Offline
          S Offline
          Sk93
          wrote on last edited by
          #4

          ;)

          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