I'm going through and replacing the previous configuration strategy in an app so that it makes more sense but it's throwing an "unrecognized attribute" exception on app load.
Here is my configuration section
using System.Configuration;
namespace MyApplication
{
public class MyConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("defaultPageIndex", DefaultValue = 1)]
[IntegerValidator(MinValue = 1)]
public int DefaultPageIndex
{
get { return (int)this["defaultPageIndex"]; }
set { this["defaultPageIndex"] = value; }
}
}
}
Here is the web.config...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="mySettingsGroup">
<section name="mySettings" type="MyApplication.MyConfigurationSection" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<mySettingsGroup defaultPageIndex="1">
</mySettingsGroup>
</configuration>
The error is Config Error Unrecognized attribute 'defaultPageIndex'
Config Source:
27:
28: <mySettingsGroup defaultPageIndex="1">
29: </mySettingsGroup>
I'm sure this something dumb that I'm just not seeing.
As a friend pointed out, the section in the group shouldn't look like this...
<mySettingsGroup defaultPageIndex="1">
</mySettingsGroup>
But rather like this...
<mySettingsGroup >
<mySettings defaultPageIndex="5"/>
</mySettingsGroup>