By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Configuration error

P: n/a
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().G etProperty("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
Oct 23 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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="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().G etProperty("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
Please, anyone?
Oct 24 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.