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