Error when trying to get section using XYZ pcmsim = (XYZ)appConfig.GetSection(“XYZ”);

The value given for the type attribute represents the assembly-qualified name of the CustomSection type.

From the Type.AssemblyQualifiedName documentation

The assembly-qualified name of a type consists of the type name,
including its namespace, followed by a comma, followed by the display
name of the assembly.

ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample from left to right consists of

  1. the namespace: ConfigurationPropertyExample
  2. the type/class name: CustomSection
  3. the displayname of the assembly containing the CustomType type: ConfigurationPropertyExample
    (Most of the time this will be the name of the assembly file without the (.dll or .exe) file extension.)

Use the Type.AssemblyQualifiedName property to retrieve a types assembly-qualified name.

var assemblyQualifiedName = typeof(CustomSection).AssemblyQualifiedName;

The returned value might include more than just the namespace, class and assembly,
like version, culture and public key token (see the specifying assembly names documentation), eg.

ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Most of the time it is not necessary to include these last ones in a configuration type definition, unless you are making use of strong-named assemblies.


In case of nested classes, a plus sign (+) will precede the nested class in the assembly-qualified name.

If the CustomSection class was defined as a nested class of a class Settings, then its assembly-qualified name would be ConfigurationPropertyExample.Settings+CustomSection, ConfigurationPropertyExample.

namespace ConfigurationPropertyExample
{
    public class Settings
    {  
        public sealed class CustomSection : ConfigurationSection
        {
            // ...
        }       
    } 
}

Browse More Popular Posts

Leave a Comment