Error while reading custom configuration file(app.config)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-04-26T11:20:08Z Indexed on 2010/04/26 11:23 UTC
Read the original article Hit count: 232

Filed under:

I am making a custom configuration in my winform application. (It will represent a country-corrency list)

First the CountryList class

namespace UtilityMethods
{
    public class CountryList : ConfigurationSection
    {
        public CountryList()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        [ConfigurationProperty("CountryCurrency", IsRequired = true)]
        public Hashtable CountryCurrencies
        {
            get
            {
                return CountryCurrency.GetCountryCurrency();
            }
        }
    }
}

The GetCountryCurrency() method is defined in CountryCurrency class as under

namespace UtilityMethods
{
    public static class CountryCurrency
    {
        public static Hashtable GetCountryCurrency()
        {
            Hashtable ht = new Hashtable();
            ht.Add("India", "Rupees");
            ht.Add("USA", "Dollar");
            return ht;
        }
    }
}

The app.config file looks like

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name ="CountryList1" type ="UtilityMethods.CountryList,CountryList,Version=2.0.0.0, 
          Culture=neutral"/>
  </configSections>
  <appSettings />

</configuration>

And I am calling this from a button_click's event as

try
            {
                CountryList cList  = ConfigurationManager.GetSection("CountryList") as CountryList;
                Hashtable ht = cList.CountryCurrencies;
            }
            catch (Exception ex)
            {
                string h = ex.Message;
            }

Upon running the application and clicking on the button I am getting this error

Could not load type 'UtilityMethods.CountryList' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Please help (dotnet framework : 3.5 Language: C#)

© Stack Overflow or respective owner

Related posts about c#3.0