Пользовательский раздел конфигурации, кажется, загружает не тот файл

Привет я создаю библиотеку (DLL), для которой я хочу загрузить файл.config (DLL_name.config) и в котором я реализовал пользовательский раздел. Я использую OpenEXEConfiguration, и он загружает файл, объект конфигурации имеет правильное значение FilePath (указывает прямо на мой файл "DLL_name.config"), но он содержит 21 раздел.net (system.net, system.web и т. Д.), Но не мой пользовательский раздел. Обратите внимание, что единственный раздел, который появляется в моем файле конфигурации, это мой пользовательский, поэтому я не понимаю, почему путь к файлу выглядит нормально, но содержимое не совпадает с тем из файла, указанного в этом пути O_o

Вот мое содержимое файла конфигурации:

<?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>

Вот мои классы разделов:

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;
        }
    }

}

Я пробовал оба

Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);

а также

ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config" };
        Configuration config2 = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

но всегда получаю один и тот же результат: filepath в порядке, но содержимое не соответствует моему вышеуказанному пользовательскому разделу...

Обратите внимание, что эта DLL-библиотека используется как плагин, расширяющий продукт под названием Sparx Enterprise Architect, поэтому она должна быть зарегистрирована для взаимодействия с COM... Не знаю, почему это будет иметь значение, но все же хотела упомянуть об этом на всякий случай:)

Любая идея относительно того, почему происходит это странное поведение, была бы очень признательна. Я всегда мог открыть файл конфигурации вручную и просмотреть XML, но это не очень элегантное решение, и я бы предпочел его избежать...

Спасибо

0 ответов

Другие вопросы по тегам