Configuration error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Configuration error

    Hello,

    I am creating a custom configuration section but I keep having the
    error:

    Unrecognized attribute 'Type'. Note that attribute names are case-
    sensitive. (...\web.config line 42)

    Line 42 is:

    <add Key="AdSense" Type="Client" Access=""/>

    This is my Web.Config code:

    <section
    name="projSetti ngs"
    type="MyApp.Con figuration.Conf ig"/>
    </configSections>
    <projSettings >
    <Google>
    <add Key="AdSense" Type="Client" Access=""/>
    <add Key="Analytics" Type="UserAccou nt" Access=""/>
    </Google>
    </projSettings>

    And I keep having the error on code line 8 in my C# code:

    1 public class Config : ConfigurationSe ction {
    2 [ConfigurationPr operty("Google" )]
    3 public GoogleCollectio n Google {
    4 get { return this["Google"] as GoogleCollectio n; }
    5 } // Google
    6
    7 public static object GetElement(Conf igSectionType type,
    string key) {
    8 object parent =
    ConfigurationMa nager.GetSectio n("projSettings ");
    9 ConfigurationEl ementCollection child =
    (ConfigurationE lementCollectio n)parent.GetTyp e().GetProperty ("projSettings" ).GetValue(pare nt,
    null);
    10 foreach (IKeyProvider element in child) {
    11 if (element.Key == key) return element;
    12 }
    13 return null;
    14 }
    15 }
    16
    17 public enum ConfigSectionTy pe {
    18 Google,
    19 Mail
    20 }
    21
    22 public class Google : ConfigurationEl ement, IKeyProvider {
    23 [ConfigurationPr operty("Key", IsRequired = true)]
    24 public string Access { get; set; }
    25 public string Key { get; set; }
    26 public string Type { get; set; }
    27 } // Google
    28
    29 public class GoogleCollectio n : ConfigurationEl ementCollection {
    30 protected override ConfigurationEl ement CreateNewElemen t() {
    31 return new Google();
    32 }
    33 protected override object GetElementKey(C onfigurationEle ment
    element) {
    34 return (element as Google).Key;
    35 } // GetElementKey
    36 }
    37
    38 interface IKeyProvider {
    39 string Key { get; set; }
    40 } // IKeyProvider

    Does anyone knows what I am doing wrong?

    I can't find the problem.

    Thanks,

    Miguel
  • shapper

    #2
    Re: Configuration error

    On Oct 23, 2:12 am, shapper <mdmo...@gmail. comwrote:
    Hello,
    >
    I am creating a custom configuration section but I keep having the
    error:
    >
    Unrecognized attribute 'Type'. Note that attribute names are case-
    sensitive. (...\web.config line 42)
    >
    Line 42 is:
    >
    <add Key="AdSense" Type="Client" Access=""/>
    >
    This is my Web.Config code:
    >
        <section
          name="projSetti ngs"
          type="MyApp.Con figuration.Conf ig"/>
      </configSections>
      <projSettings >
        <Google>
          <add Key="AdSense" Type="Client" Access=""/>
          <add Key="Analytics" Type="UserAccou nt" Access=""/>
        </Google>
      </projSettings>
    >
    And I keep having the error on code line 8 in my C# code:
    >
    1      public class Config : ConfigurationSe ction {
    2        [ConfigurationPr operty("Google" )]
    3        public GoogleCollectio n Google {
    4          get { return this["Google"] as GoogleCollectio n; }
    5        } // Google
    6
    7        public static object GetElement(Conf igSectionType type,
    string key) {
    8          object parent =
    ConfigurationMa nager.GetSectio n("projSettings ");
    9          ConfigurationEl ementCollection child =
    (ConfigurationE lementCollectio n)parent.GetTyp e().GetProperty ("projSettings" ).GetValue(pare nt,
    null);
    10         foreach (IKeyProvider element in child) {
    11           if (element.Key == key) return element;
    12         }
    13         return null;
    14       }
    15     }
    16
    17     public enum ConfigSectionTy pe {
    18       Google,
    19       Mail
    20     }
    21
    22     public class Google : ConfigurationEl ement, IKeyProvider {
    23       [ConfigurationPr operty("Key", IsRequired = true)]
    24       public string Access { get; set; }
    25       public string Key { get; set; }
    26       public string Type { get; set; }
    27     } // Google
    28
    29    public class GoogleCollectio n : ConfigurationEl ementCollection {
    30       protected override ConfigurationEl ement CreateNewElemen t(){
    31         return new Google();
    32       }
    33       protected override object GetElementKey(C onfigurationEle ment
    element) {
    34         return (element as Google).Key;
    35       } // GetElementKey
    36     }
    37
    38     interface IKeyProvider {
    39       string Key { get; set; }
    40     } // IKeyProvider
    >
    Does anyone knows what I am doing wrong?
    >
    I can't find the problem.
    >
    Thanks,
    >
    Miguel
    Please, anyone?

    Comment

    Working...