Plik App.Config z własną sekcją

0

Witam,

Zdefiniowałem w programie klasę sekcji:

    public class ProjectConfigurationSection : System.Configuration.ConfigurationSection
    {
        public ProjectConfigurationSection()
        {
        }








        #region Property


        [
            System.Configuration.ConfigurationProperty("projectElement")
        ]
        public string ProjectElements
        {
            set
            {
                this["projectElements"] = value;
            }


            get
            {
                return (string)this["projectElements"];
            }
        }


        #endregion
    }

która przechowywać ma jedną zmienną typu string. Dla samego programu powstał plik App.Config o zawartości:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="projectSection" type="Test.Configuration.ProjectConfigurationSection, Test, Version=null, Culture=neutral, PublicKeyToken=null" />
  </configSections>


  
  
  <projectSection projectElement="Helo" />
</configuration>

Do tego wszystkiego z CodeProject wykorzystałem metodę, która jak przypuszczałem miała mi zwróci zawartość całego configa:

            var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);



            System.Configuration.ConfigurationSectionGroupCollection sectionGroups = config.SectionGroups;


            ClientSettingsSection clientSection;
        SettingValueElement value;

        foreach(ConfigurationSectionGroup group in sectionGroups)
        // Loop over all groups

        {
            if(!group.IsDeclared)
            // Only the ones which are actually defined in app.config

              continue;

            System.Diagnostics.Debug.WriteLine
                (
                string.Format("Group {0}", group.Name)
                );

               // get all sections inside group

            foreach (ConfigurationSection section in group.Sections)
            {
                clientSection = section as ClientSettingsSection;
                System.Diagnostics.Debug.WriteLine
                    (
                    string.Format("\tSection: {0}", section)
                );

                if (clientSection == null)
                    continue;


                foreach (SettingElement set in clientSection.Settings)
                {
                    value = set.Value as SettingValueElement;
                    // print out value of each section

                    System.Diagnostics.Debug.WriteLine
                        (
                        string.Format("\t\t{0}: {1}",
                    set.Name, value.ValueXml.InnerText)
                    );
                }
            }

Niestety to wszystko nie bardzo chce mi współpracować. Dodatkowo zaznaczę, że próbowałem wywołać także plik konfiguracji z odwołaniem do niego w taki sposób:

OpenExeConfiguration("App.Config");

co też nie działało.

Poproszę Was o pomoc i wskazanie gdzie robię błąd.

Pozdrawiam,
Grzegorz

1 użytkowników online, w tym zalogowanych: 0, gości: 1