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

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
shapper said:
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 Web.Config: ....
<projSettings>
<Google>
<add Key="AdSense" Type="Client" Access="one"/>
<add Key="Analytics" Type="UserAccount" Access="two"/>
</Google>
</projSettings>
....
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?
 
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 Web.Config: ...
 <projSettings>
   <Google>
     <add Key="AdSense" Type="Client" Access="one"/>
     <add Key="Analytics" Type="UserAccount" Access="two"/>
   </Google>
 </projSettings>
...
 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?

Yes, I found the problem and it is exactly that!

Thanks,
Miguel
 
Back
Top