S
shapper
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="projSettings"
type="MyApp.Configuration.Config"/>
</configSections>
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access=""/>
<add Key="Analytics" Type="UserAccount" Access=""/>
</Google>
</projSettings>
And I keep having the error on code line 8 in my C# code:
1 public class Config : ConfigurationSection {
2 [ConfigurationProperty("Google")]
3 public GoogleCollection Google {
4 get { return this["Google"] as GoogleCollection; }
5 } // Google
6
7 public static object GetElement(ConfigSectionType type,
string key) {
8 object parent =
ConfigurationManager.GetSection("projSettings");
9 ConfigurationElementCollection child =
(ConfigurationElementCollection)parent.GetType().GetProperty("projSettings").GetValue(parent,
null);
10 foreach (IKeyProvider element in child) {
11 if (element.Key == key) return element;
12 }
13 return null;
14 }
15 }
16
17 public enum ConfigSectionType {
18 Google,
19 Mail
20 }
21
22 public class Google : ConfigurationElement, IKeyProvider {
23 [ConfigurationProperty("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 GoogleCollection : ConfigurationElementCollection {
30 protected override ConfigurationElement CreateNewElement() {
31 return new Google();
32 }
33 protected override object GetElementKey(ConfigurationElement
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
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="projSettings"
type="MyApp.Configuration.Config"/>
</configSections>
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access=""/>
<add Key="Analytics" Type="UserAccount" Access=""/>
</Google>
</projSettings>
And I keep having the error on code line 8 in my C# code:
1 public class Config : ConfigurationSection {
2 [ConfigurationProperty("Google")]
3 public GoogleCollection Google {
4 get { return this["Google"] as GoogleCollection; }
5 } // Google
6
7 public static object GetElement(ConfigSectionType type,
string key) {
8 object parent =
ConfigurationManager.GetSection("projSettings");
9 ConfigurationElementCollection child =
(ConfigurationElementCollection)parent.GetType().GetProperty("projSettings").GetValue(parent,
null);
10 foreach (IKeyProvider element in child) {
11 if (element.Key == key) return element;
12 }
13 return null;
14 }
15 }
16
17 public enum ConfigSectionType {
18 Google,
19 Mail
20 }
21
22 public class Google : ConfigurationElement, IKeyProvider {
23 [ConfigurationProperty("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 GoogleCollection : ConfigurationElementCollection {
30 protected override ConfigurationElement CreateNewElement() {
31 return new Google();
32 }
33 protected override object GetElementKey(ConfigurationElement
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