Hi I'm creating a library (DLL) for which I want to load the .config file (DLL_name.config) and in which I have implemented a custom section. I'm using OpenEXEConfiguration and it loads the file, Configuration object has the right FilePath value (pointing straight to my "DLL_name.config" file), but it contains 21 .net sections (system.net, system.web, etc) but not my custom section. Note that the only section appearing in my config file is my custom one, so I don't understand why the file path seem ok but the content is not the one from the file specified in that path O_o
Here is my config file content:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="AcceptedStereotypesSection" type="EAReferentialAddInConfigs.CustomConfigs.IntegrityCheck.AcceptedStereotypesSection, EAReferentialAddInConfigs"/>
</configSections>
<AcceptedStereotypesSection>
<AcceptedStereotypes>
<AcceptedStereotype Stereotype="Test1">
</AcceptedStereotype>
</AcceptedStereotypes>
</AcceptedStereotypesSection>
</configuration>
Here's my custom section classes:
public class AcceptedStereotypesSection: ConfigurationSection
{
[ConfigurationProperty("AcceptedStereotypes", IsDefaultCollection = true, IsKey = false, IsRequired = true)]
public AcceptedStereotypeCollection AcceptedStereotypes
{
get
{
return base["AcceptedStereotypes"] as AcceptedStereotypeCollection;
}
set
{
base["AcceptedStereotypes"] = value;
}
}
}
public class AcceptedStereotypeCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new AcceptedStereotype();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((AcceptedStereotype)element).Stereotype;
}
protected override string ElementName
{
get
{
return "AcceptedStereotype";
}
}
protected override bool IsElementName(string elementName)
{
return !String.IsNullOrEmpty(elementName) && elementName == ElementName;
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}
public AcceptedStereotype this[int index]
{
get
{
return base.BaseGet(index) as AcceptedStereotype;
}
}
public new AcceptedStereotype this[string key]
{
get
{
return base.BaseGet(key) as AcceptedStereotype;
}
}
}
public class AcceptedStereotype:ConfigurationElement
{
[ConfigurationProperty("Stereotype", IsKey = true)]
public String Stereotype
{
get
{
return (String)this["Stereotype"];
}
}
[ConfigurationProperty("AcceptedRelationships", IsDefaultCollection = true, IsKey = false, IsRequired = true)]
public AcceptedRelationshipCollection AcceptedRelationships
{
get
{
return base["AcceptedRelationships"] as AcceptedRelationshipCollection;
}
set
{
base["AcceptedRelationships"] = value;
}
}
}
I've tried both
Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
and
ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config" };
Configuration config2 = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
but always getting same result: filepath is ok but content does not represent my above custom section...
Note that this DLL is used as a plugin extending a product named Sparx Enterprise Architect, so is has to be registered for COM interop... Dunno why that would make a difference but still wanted to mention it just in case :)
Any idea as to why this strange behavior occurs would be very appreciated. I could always open up the config file manually and browse the XML, but this is not a very elegant solution and would rather avoid it...
Thanks