0
votes

I am trying to read in my own custom values from the App.config, but I keep getting an error saying the following:

Could not load type 'StockCSV.CordnersConfiguration' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Any help would be great, thanks in advance!

Config

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <sectionGroup name="CordnerConfigurationSection">
          <section 
            name="cordnerConfig" 
            type="StockCSV.CordnersConfiguration.CordnerConfigurationSection, StockCSV.CordnersConfiguration" 
            allowLocation="false" 
            allowDefinition="Everywhere" />
        </sectionGroup>
      </configSections>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
        </startup>
      <CordnerConfigurationSection>
        <cordnerConfig Location="C:\Users\Conor\Desktop\Cordners Data Dump\stocknew.csv"></cordnerConfig>
      </CordnerConfigurationSection>
</configuration>

Code

namespace StockCSV.CordnersConfiguration
{
    public class CordnerConfigurationSection : ConfigurationSection
    {
        private static CordnerConfigurationSection cordnerConfig = (CordnerConfigurationSection)System.Configuration.ConfigurationManager.GetSection("CordnerConfigurationSection/cordnerConfig");

        private const string OutputPathProviderName = "outputPath";

        public static CordnerConfigurationSection CordnerConfig => cordnerConfig;

        [ConfigurationProperty(OutputPathProviderName)]
        public OutputConfigurationElement OutputLocation
        {
            get => (OutputConfigurationElement) this[OutputPathProviderName];
            set => this[OutputPathProviderName] = value;
        }
    }
}
1

1 Answers

0
votes

Custom config sections must follow the below pattern, as per documentation

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

In your case, the config type may be set incorrectly. Check spelling are correct, particularly the name of the assembly is correct.

I believe, your type should be

     type="StockCSV.CordnersConfiguration.CordnerConfigurationSection, StockCSV"

Let me know if that solves it or not.