S
shapper
Hello,
On a custom Web.Config section I keep having the same error. This is
driving me crazy!!!
I keep having the following error:
Unrecognized attribute 'Type'. Note that attribute names are case-
sensitive. (C:\Documents and Settings\Miguel\My Documents\Website
\web.config line 42)
On code line:
object parent = ConfigurationManager.GetSection("projSettings");
And Web.Config line 42 is:
<add Key="AdSense" Type="Client" Access="one"/>
This is my test code to read an item of Google group in my Custom
Section:
bool found;
object parent =
ConfigurationManager.GetSection("projSettings");
ConfigurationElementCollection child =
(ConfigurationElementCollection)parent.GetType().GetProperty("projSettings").GetValue(parent,
null);
foreach (IKeyProvider element in child) {
if (element.Key == "AdSense") found = true;
}
This is my Web.Config:
...
<section
name="projSettings"
type="MyApp.Configuration.ProjSettingsSection"/>
</configSections>
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access="one"/>
<add Key="Analytics" Type="UserAccount" Access="two"/>
</Google>
</projSettings>
This is my custom configuration section class:
public class ProjSettingsSection : ConfigurationSection {
[ConfigurationProperty("Google")]
public GoogleCollection Google {
get { return this["Google"] as GoogleCollection; }
}
}
public class GoogleCollection : ConfigurationElementCollection {
protected override ConfigurationElement CreateNewElement() {
return new Google();
}
protected override object GetElementKey(ConfigurationElement
element) {
return (element as Google).Key;
}
}
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key { get; set; }
public string Type { get; set; }
public string Access { get; set; }
}
interface IKeyProvider {
string Key { get; set; }
}
I really tried everything I could think of for the past 2 weeks or
so ...
.... Every time I get free time I go back to this.
I get always the same error.
Could someone, please, help me out?
Thanks,
Miguel
On a custom Web.Config section I keep having the same error. This is
driving me crazy!!!
I keep having the following error:
Unrecognized attribute 'Type'. Note that attribute names are case-
sensitive. (C:\Documents and Settings\Miguel\My Documents\Website
\web.config line 42)
On code line:
object parent = ConfigurationManager.GetSection("projSettings");
And Web.Config line 42 is:
<add Key="AdSense" Type="Client" Access="one"/>
This is my test code to read an item of Google group in my Custom
Section:
bool found;
object parent =
ConfigurationManager.GetSection("projSettings");
ConfigurationElementCollection child =
(ConfigurationElementCollection)parent.GetType().GetProperty("projSettings").GetValue(parent,
null);
foreach (IKeyProvider element in child) {
if (element.Key == "AdSense") found = true;
}
This is my Web.Config:
...
<section
name="projSettings"
type="MyApp.Configuration.ProjSettingsSection"/>
</configSections>
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access="one"/>
<add Key="Analytics" Type="UserAccount" Access="two"/>
</Google>
</projSettings>
This is my custom configuration section class:
public class ProjSettingsSection : ConfigurationSection {
[ConfigurationProperty("Google")]
public GoogleCollection Google {
get { return this["Google"] as GoogleCollection; }
}
}
public class GoogleCollection : ConfigurationElementCollection {
protected override ConfigurationElement CreateNewElement() {
return new Google();
}
protected override object GetElementKey(ConfigurationElement
element) {
return (element as Google).Key;
}
}
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key { get; set; }
public string Type { get; set; }
public string Access { get; set; }
}
interface IKeyProvider {
string Key { get; set; }
}
I really tried everything I could think of for the past 2 weeks or
so ...
.... Every time I get free time I go back to this.
I get always the same error.
Could someone, please, help me out?
Thanks,
Miguel