Custom config sections problem.
-
This problem is giving me a lot of headaches and can´t find the solution... I´m reading this article Custom Configuration Sections for Lazy Coders[^] I´m reading the part titled "The Hello, World ConfigurationSection" , using exactly same code (copy paste directly) and always obtain an error when execute the program (it not returns error/warnings on compiling time). The error says that can´t load config.SomeSettings from asembly... My app.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="config.SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration>
Proyect --> properties , shows me that the name of my assembly is "config" I´m totally lost, found more codes similar to the one explained into this article and always, ALWAYS, always obtain the same error.... perhaps someone can give me a hand, thanks :) -
This problem is giving me a lot of headaches and can´t find the solution... I´m reading this article Custom Configuration Sections for Lazy Coders[^] I´m reading the part titled "The Hello, World ConfigurationSection" , using exactly same code (copy paste directly) and always obtain an error when execute the program (it not returns error/warnings on compiling time). The error says that can´t load config.SomeSettings from asembly... My app.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="config.SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration>
Proyect --> properties , shows me that the name of my assembly is "config" I´m totally lost, found more codes similar to the one explained into this article and always, ALWAYS, always obtain the same error.... perhaps someone can give me a hand, thanks :)Just a quick check, but your
namespace
that the class sits in is definatelyconfig
right? Eg, the code should look something like this:using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace config
{
public class SomeSettings : ConfigurationSection
{
private SomeSettings() { }\[ConfigurationProperty("FillColor", DefaultValue = "Cyan")\] public System.Drawing.Color FillColor { get { return (System.Drawing.Color)this\["FillColor"\]; } set { this\["FillColor"\] = value; } } \[ConfigurationProperty("TextSize", DefaultValue = "8.5")\] public float TextSize { get { return (float)this\["TextSize"\]; } set { this\["TextSize"\] = value; } } \[ConfigurationProperty("FillOpacity", DefaultValue = "40")\] public byte FillOpacity { get { return (byte)this\["FillOpacity"\]; } set { this\["FillOpacity"\] = value; } } }
}
-
Just a quick check, but your
namespace
that the class sits in is definatelyconfig
right? Eg, the code should look something like this:using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace config
{
public class SomeSettings : ConfigurationSection
{
private SomeSettings() { }\[ConfigurationProperty("FillColor", DefaultValue = "Cyan")\] public System.Drawing.Color FillColor { get { return (System.Drawing.Color)this\["FillColor"\]; } set { this\["FillColor"\] = value; } } \[ConfigurationProperty("TextSize", DefaultValue = "8.5")\] public float TextSize { get { return (float)this\["TextSize"\]; } set { this\["TextSize"\] = value; } } \[ConfigurationProperty("FillOpacity", DefaultValue = "40")\] public byte FillOpacity { get { return (byte)this\["FillOpacity"\]; } set { this\["FillOpacity"\] = value; } } }
}
I solved it definetly... i not defined any namespace, so the problem was in App.config...
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration>
And all works good :) -
I solved it definetly... i not defined any namespace, so the problem was in App.config...
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="SomeSettings" type="SomeSettings, config" /> </configSections> <SomeSettings FillColor="LightBlue" TextSize="9.5" FillOpacity="50" /> </configuration>
And all works good :)