1

So im completely new to using the app-config file , im trying to create a custom configuration handler so that I can read multiple values from the same key , I followed the documentation on the Microsoft website but ive run into a problem.

Every time I try run my code it throws this error

"Unrecognized attribute 'datatype'. Note that attribute names are case-sensitive. (C:\Users\stephen.carmody\Desktop\FlatFileFactory - Copy\FlatFileFactory\bin\Debug\FlatFileFactory.vshost.exe.Config line 21)"

It only seems to recognize the first two values in the element, the third "datatype" throws the error

Here is a look at my config file

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- Configuration section-handler declaration area. -->
 <configSections>
  <sectionGroup name="propertyValuesGroup">
  <section
    name="propertyValues"
    type="FlatFileTestCaseAutomater.CustomConfigurationSectionHandler,FlatFileFactory"
    allowLocation="true"
    allowDefinition="Everywhere"
  />
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>

<!-- Configuration section settings area. -->


<propertyValuesGroup>
<propertyValues>
  <cHeaderProperty name="txnNo" nullable="yes" datatype="int" maxlength="" />
</propertyValues>
</propertyValuesGroup>

</configuration>

Here is look at my custom handler class:

namespace FlatFileTestCaseAutomater
{
    class CustomConfigurationSectionHandler : ConfigurationSection
    {
        [ConfigurationProperty("cHeaderProperty")]
        public CHeaderPropertyElement Property
    {
        get
        {
            return (CHeaderPropertyElement)this["cHeaderProperty"];
        }
        set
        { this["cHeaderProperty"] = value; }
    }
}


public class ClaimHeaderElement : ConfigurationElement
{
    [ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    public String Name
    {
        get
        {
            return (String)this["name"];
        }
        set
        {
            this["name"] = value;
        }
    }

    [ConfigurationProperty("dataType", DefaultValue = "", IsRequired = true)]
    [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    public String DataType
    {
        get
        {
            return (String)this["dataType"];
        }
        set
        {
            this["dataType"] = value;
        }
    }

    [ConfigurationProperty("maxLength", DefaultValue = int.MaxValue, IsRequired = false)]
   // [IntegerValidator(ExcludeRange = false, MaxValue = 24, MinValue = 0)]
    public int MaxLength
    {
        get
        { return (int)this["maxLength"]; }
        set
        { this["maxLength"] = value; }
    }

}

}

Here is the snippet of code where the break occurs during debug:

  FlatFileTestCaseAutomater.CustomConfigurationSectionHandler config =
    (FlatFileTestCaseAutomater.CustomConfigurationSectionHandler)System.Configuration.ConfigurationManager.GetSection(
    "propertyValuesGroup/propertyValues");

I know a similar thread has been posted before but I've been at this for hours now with no luck

Steve2056726
  • 457
  • 2
  • 6
  • 20

1 Answers1

0

I may be wrong but your names in the config don't seem of the same 'case', they're all lower-case (datatype and maxlength), typo when pasting here?

Attributes are indeed case-sensitive - and it should be (based on your code)

<cHeaderProperty name="txnNo" nullable="yes" dataType="int" maxLength="" />
NSGaga-mostly-inactive
  • 14,052
  • 3
  • 41
  • 51
  • That was a mistake , I originally had them matching, still doesnt work. According to this [link]http://msdn.microsoft.com/en-us/library/2tw134k3.aspx[/link] I should be able to call values like this - config.Property.MaxLenth , however maxLength isnt an available option when i type in config.Property. – Steve2056726 Apr 25 '13 at 19:06