2017-02-01 4 views
0

Ich gehe durch und ersetze die vorherige Konfigurationsstrategie in einer App, so dass es sinnvoller ist, aber es eine "unerkannte Attribut" Ausnahme bei App laden wirft.Benutzerdefinierte KonfigurationSection wirft unbekanntes Attribut in web.config

Hier ist meine Konfiguration Abschnitt

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

ist die 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> 

Der Fehler Config Error Unrecognized attribute 'defaultPageIndex'

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

Ich bin sicher, dass dies etwas ist dumm das sehe ich einfach nicht.

Antwort

0

Als Freund wies darauf hin, wobei der Schnitt in der Gruppe sollte nicht so aussehen ...

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

aber eher so ...

<mySettingsGroup > 
    <mySettings defaultPageIndex="5"/> 
</mySettingsGroup> 
Verwandte Themen