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. .NET (Core and Framework)
  4. ConfigurationManager: ConfigurationErrorsException after removing config attribute? [RESOLVED]

ConfigurationManager: ConfigurationErrorsException after removing config attribute? [RESOLVED]

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionlearningworkspace
8 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.
  • H Offline
    H Offline
    Homncruse
    wrote on last edited by
    #1

    Exception message: "Unrecognized attribute 'valid'. Note that attribute names are case-sensitive. I used to have a field called "valid" in one of my configuration elements, but through the course of development it's now obsolete, so I'd like to remove it. I removed it from the ConfigurationElement subclass, and now when I try to read the config section (via config.GetSection), I get the above exception, which then makes my config section variable null, blah blah blah, no saved config = program effectively unusable from session to session. Google fails me. MSDN fails me. Internet fails me. I'm new to the ConfigurationManager, having only ever done equivalent functionality through .ini files before, so I'm sure there's probably just some "cleanup" command I can do that I'm just not aware of.

    modified on Friday, October 23, 2009 2:41 PM

    L 1 Reply Last reply
    0
    • H Homncruse

      Exception message: "Unrecognized attribute 'valid'. Note that attribute names are case-sensitive. I used to have a field called "valid" in one of my configuration elements, but through the course of development it's now obsolete, so I'd like to remove it. I removed it from the ConfigurationElement subclass, and now when I try to read the config section (via config.GetSection), I get the above exception, which then makes my config section variable null, blah blah blah, no saved config = program effectively unusable from session to session. Google fails me. MSDN fails me. Internet fails me. I'm new to the ConfigurationManager, having only ever done equivalent functionality through .ini files before, so I'm sure there's probably just some "cleanup" command I can do that I'm just not aware of.

      modified on Friday, October 23, 2009 2:41 PM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I believe you are writing a class to read configuration values from a config class. You have removed the 'valid' element from the spec but not from the config file. I think, removing the 'valid' element from the config file should solve your problem.

      H 1 Reply Last reply
      0
      • L Lost User

        I believe you are writing a class to read configuration values from a config class. You have removed the 'valid' element from the spec but not from the config file. I think, removing the 'valid' element from the config file should solve your problem.

        H Offline
        H Offline
        Homncruse
        wrote on last edited by
        #3

        Yes, that's more or less the problem, but since it's using the ConfigurationManager, the actual config file operations are completely hidden (as far as I know), or at least I don't know where to find it.

        L 1 Reply Last reply
        0
        • H Homncruse

          Yes, that's more or less the problem, but since it's using the ConfigurationManager, the actual config file operations are completely hidden (as far as I know), or at least I don't know where to find it.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What kind of app r u developing? Windows or Web ? Whatever it is you should have full control over your config files.

          H 1 Reply Last reply
          0
          • L Lost User

            What kind of app r u developing? Windows or Web ? Whatever it is you should have full control over your config files.

            H Offline
            H Offline
            Homncruse
            wrote on last edited by
            #5

            It's a Windows app using the built-in ConfigurationManager .NET capabilities. I based it on this MSDN code sample[^]. Maybe it'll be easier to just show some code: Configuration classes:

            public class SerialConfig : ConfigurationElement
            {
            /* *********************************** */
            /* This is the field I want to remove! */
            /* *********************************** */
            // Fields
            [ConfigurationProperty("valid",
            DefaultValue = false,
            IsRequired = false)]
            //private int baud;
            public bool Valid
            {
            get
            {
            return (bool)this["valid"];
            }
            set
            {
            this["valid"] = (bool)value;
            }
            }

                \[ConfigurationProperty("baud",
                    DefaultValue = 115200,
                    IsRequired = true)\]
                //private int baud;
                public int Baud
                {
                    get
                    {
                        return (int)this\["baud"\];
                    }
                    set
                    {
                        if((value == 115200) || (value == 9600))
                        {
                            this\["baud"\] = value;
                        }
                        else
                        {
                        }
                    }
                }
            
                \[ConfigurationProperty("name",
                    DefaultValue = "",
                    IsRequired = true)\]
                //private String name;
                public String Name
                {
                    get
                    {
                        return (string)this\["name"\];
                    }
                    set
                    {
                        if (value.Contains("COM"))
                        {
                            this\["name"\] = value;
                        }
                        else
                        {
                            this\["name"\] = "INVALID";
                        }
                    }
                }
                
                // Constructors
                public SerialConfig(String name, int baud)
                {
                    this\["baud"\] = baud;
                    this\["name"\] = name;            
                }
            
                public SerialConfig(string name)
                {
                    new SerialConfig(name, 115200);
                }
            
                public SerialConfig()
                {
                    new SerialConfig("INVALID", 115200);
                }
            }
            
            // Define a c
            
            L 2 Replies Last reply
            0
            • H Homncruse

              It's a Windows app using the built-in ConfigurationManager .NET capabilities. I based it on this MSDN code sample[^]. Maybe it'll be easier to just show some code: Configuration classes:

              public class SerialConfig : ConfigurationElement
              {
              /* *********************************** */
              /* This is the field I want to remove! */
              /* *********************************** */
              // Fields
              [ConfigurationProperty("valid",
              DefaultValue = false,
              IsRequired = false)]
              //private int baud;
              public bool Valid
              {
              get
              {
              return (bool)this["valid"];
              }
              set
              {
              this["valid"] = (bool)value;
              }
              }

                  \[ConfigurationProperty("baud",
                      DefaultValue = 115200,
                      IsRequired = true)\]
                  //private int baud;
                  public int Baud
                  {
                      get
                      {
                          return (int)this\["baud"\];
                      }
                      set
                      {
                          if((value == 115200) || (value == 9600))
                          {
                              this\["baud"\] = value;
                          }
                          else
                          {
                          }
                      }
                  }
              
                  \[ConfigurationProperty("name",
                      DefaultValue = "",
                      IsRequired = true)\]
                  //private String name;
                  public String Name
                  {
                      get
                      {
                          return (string)this\["name"\];
                      }
                      set
                      {
                          if (value.Contains("COM"))
                          {
                              this\["name"\] = value;
                          }
                          else
                          {
                              this\["name"\] = "INVALID";
                          }
                      }
                  }
                  
                  // Constructors
                  public SerialConfig(String name, int baud)
                  {
                      this\["baud"\] = baud;
                      this\["name"\] = name;            
                  }
              
                  public SerialConfig(string name)
                  {
                      new SerialConfig(name, 115200);
                  }
              
                  public SerialConfig()
                  {
                      new SerialConfig("INVALID", 115200);
                  }
              }
              
              // Define a c
              
              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Your solution must have a default configuration file (app.config) that is used as a template to create local copies during deployment. For example, if you app name is myapp.exe, then your configuration file name during deployment is myapp.exe.config. Changing the app.config should solve your problem.

              1 Reply Last reply
              0
              • H Homncruse

                It's a Windows app using the built-in ConfigurationManager .NET capabilities. I based it on this MSDN code sample[^]. Maybe it'll be easier to just show some code: Configuration classes:

                public class SerialConfig : ConfigurationElement
                {
                /* *********************************** */
                /* This is the field I want to remove! */
                /* *********************************** */
                // Fields
                [ConfigurationProperty("valid",
                DefaultValue = false,
                IsRequired = false)]
                //private int baud;
                public bool Valid
                {
                get
                {
                return (bool)this["valid"];
                }
                set
                {
                this["valid"] = (bool)value;
                }
                }

                    \[ConfigurationProperty("baud",
                        DefaultValue = 115200,
                        IsRequired = true)\]
                    //private int baud;
                    public int Baud
                    {
                        get
                        {
                            return (int)this\["baud"\];
                        }
                        set
                        {
                            if((value == 115200) || (value == 9600))
                            {
                                this\["baud"\] = value;
                            }
                            else
                            {
                            }
                        }
                    }
                
                    \[ConfigurationProperty("name",
                        DefaultValue = "",
                        IsRequired = true)\]
                    //private String name;
                    public String Name
                    {
                        get
                        {
                            return (string)this\["name"\];
                        }
                        set
                        {
                            if (value.Contains("COM"))
                            {
                                this\["name"\] = value;
                            }
                            else
                            {
                                this\["name"\] = "INVALID";
                            }
                        }
                    }
                    
                    // Constructors
                    public SerialConfig(String name, int baud)
                    {
                        this\["baud"\] = baud;
                        this\["name"\] = name;            
                    }
                
                    public SerialConfig(string name)
                    {
                        new SerialConfig(name, 115200);
                    }
                
                    public SerialConfig()
                    {
                        new SerialConfig("INVALID", 115200);
                    }
                }
                
                // Define a c
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                In the InitializeConfig() method, debug and check the value of userConfig.FilePath property. I think that should tell you the configuration file path.

                H 1 Reply Last reply
                0
                • L Lost User

                  In the InitializeConfig() method, debug and check the value of userConfig.FilePath property. I think that should tell you the configuration file path.

                  H Offline
                  H Offline
                  Homncruse
                  wrote on last edited by
                  #8

                  Thank you! That finally resolved the issue. I knew it had to be lingering around somewhere.

                  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