Connecting Tech Pros Worldwide Forums | Help | Site Map

Custom Configuration. Help me, please, to spot the problem. ThankYou.

shapper
Guest
 
Posts: n/a
#1: Nov 6 '08
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().G etProperty("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

John Saunders
Guest
 
Posts: n/a
#2: Nov 7 '08

re: Custom Configuration. Help me, please, to spot the problem. ThankYou.


"shapper" <mdmoura@gmail.comwrote in message
news:d97dc93c-48d8-4327-b1a2-2aaa8e227f01@b2g2000prf.googlegroups.com...
Quote:
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"/>
>
....
Quote:
This is my Web.Config:
....
Quote:
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access="one"/>
<add Key="Analytics" Type="UserAccount" Access="two"/>
</Google>
</projSettings>
>
....
Quote:
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key { get; set; }
public string Type { get; set; }
public string Access { get; set; }
}
What happens if you use a ConfigurationProperty attribute on Type and
Access?

--
John Saunders | MVP - Connected System Developer

shapper
Guest
 
Posts: n/a
#3: Nov 7 '08

re: Custom Configuration. Help me, please, to spot the problem. ThankYou.


On Nov 7, 1:55*am, "John Saunders" <n...@dont.do.that.comwrote:
Quote:
"shapper" <mdmo...@gmail.comwrote in message
>
news:d97dc93c-48d8-4327-b1a2-2aaa8e227f01@b2g2000prf.googlegroups.com...
>
>
>
Quote:
Hello,
>
Quote:
On a custom Web.Config section I keep having the same error. This is
driving me crazy!!!
>
Quote:
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)
>
Quote:
On code line:
object parent = ConfigurationManager.GetSection("projSettings");
>
Quote:
And Web.Config line 42 is:
*<add Key="AdSense" Type="Client" Access="one"/>
>
...
Quote:
This is my Web.Config:
...
Quote:
*<projSettings>
* *<Google>
* * *<add Key="AdSense" Type="Client" Access="one"/>
* * *<add Key="Analytics" Type="UserAccount" Access="two"/>
* *</Google>
*</projSettings>
>
...
Quote:
*public class Google : ConfigurationElement, IKeyProvider {
* *[ConfigurationProperty("Key", IsRequired = true)]
* *public string Key { get; set; }
* *public string Type { get; set; }
* *public string Access { get; set; }
*}
>
What happens if you use a ConfigurationProperty attribute on Type and
Access?
>
--
John Saunders | MVP - Connected System Developer
Yes, I found the problem and it is exactly that!

Thanks,
Miguel
Closed Thread