Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error reading configuration: Could not load type ... from assembly 'System.Configuration

Tags:

c#

I am at a loss... Getting an error when calling

 var mySettings = ListOfOrgs.GetSettings();

Could not load type 'DetailedFaxByMonthByOrg.ListOfOrgsSection' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.":"DetailedFaxByMonthByOrg.ListOfOrgsSection"}

Can someone help?

Config:

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
          <section name="ListOfOrgs" type="DetailedFaxByMonthByOrg.ListOfOrgsSection"/>

      </configSections>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>


      <ListOfOrgs>
        <Settings>
          <add name="myComp" userIds="12345,123475" GBuserIds="99999"></add>
          <add name="myComp2" userIds=" 58795,25362" GBuserIds="254300, 956482"></add>
        </Settings>
      </ListOfOrgs>
    </configuration>

Code:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DetailedFaxByMonthByOrg
{
    public class ListOfOrgs
    {
        public static ListOfOrgsSection _Config = ConfigurationManager.GetSection("ListOfOrgs") as ListOfOrgsSection;
        public static SettingsElementCollection GetSettings()
        {
            return _Config.Settings;
        }
    }
    public class ListOfOrgsSection : ConfigurationSection
    {
        [ConfigurationProperty("Settings")]
        public SettingsElementCollection Settings
        {
            get { return (SettingsElementCollection)this["Settings"]; }
        }
    }

    [ConfigurationCollection(typeof(OrgElement))]
    public class SettingsElementCollection : ConfigurationElementCollection
    {
        public OrgElement this[int index]
        {
            get { return (OrgElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                    BaseRemoveAt(index);

                BaseAdd(index, value);
            }
        }
        protected override ConfigurationElement CreateNewElement()
        {
            return new OrgElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((OrgElement)element).Name;
        }
    }
    public class OrgElement : ConfigurationElement
    {
        public OrgElement() { }

        [ConfigurationProperty("name", DefaultValue = "", IsKey = true, IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }

        [ConfigurationProperty("userIds", DefaultValue = "", IsRequired = true)]
        public string userIds
        {
            get { return (string)this["userIds"]; }
            set { this["userIds"] = value; }
        }

        [ConfigurationProperty("GBuserIds", DefaultValue = "", IsRequired = true)]
        public string GBuserIds
        {
            get { return (string)this["GBuserIds"]; }
            set { this["GBuserIds"] = value; }
        }

    }
}
like image 647
user3520042 Avatar asked Apr 10 '14 15:04

user3520042


1 Answers

per the documentation:

<section 
   name="section name"
   type="configuration section handler class, assembly file name, version, culture, public key token"
 .....
 />

update your configSection definition to

<section name="ListOfOrgs" type="DetailedFaxByMonthByOrg.ListOfOrgsSection, DetailedFaxByMonthByOrg">

It's looking in the wrong assembly

like image 120
Jonesopolis Avatar answered Nov 07 '22 19:11

Jonesopolis