0

我正在检查并替换应用程序中以前的配置策略,以使其更有意义,但它会在应用程序加载时引发“无法识别的属性”异常。

这是我的配置部分

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; }
        }
    }
}

这是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>

错误是Config Error Unrecognized attribute 'defaultPageIndex'

Config Source:
   27: 
   28:     <mySettingsGroup defaultPageIndex="1">
   29:     </mySettingsGroup>

我敢肯定这是我没有看到的愚蠢的东西。

4

1 回答 1

0

正如朋友指出的那样,组中的部分不应该是这样的......

<mySettingsGroup defaultPageIndex="1">
</mySettingsGroup>

而是像这样...

<mySettingsGroup >
    <mySettings defaultPageIndex="5"/>
</mySettingsGroup>
于 2017-02-03T17:34:27.047 回答