1

Configuration設定を簡単に読み書きして呼び出すことができSave(ConfigurationSaveMode.Minimal, true)、通常は問題なく動作 するオブジェクトがあります。

sectionGroupただし、カスタム定義のタイプを持つ構成ファイルがありますSystem.Configuration.NameValueSectionHandler(その部分を作成していないため、変更できません)。Saveメソッドを呼び出すと、TypeLoadException

メッセージ:

タイプ System.Configuration.NameValueSectionHandler は から継承されません System.Configuration.ConfigurationSectionGroup

コールスタック:

at System.Configuration.TypeUtil.VerifyAssignableType
      (Type baseType, Type type, Boolean throwOnError)
at System.Configuration.TypeUtil.GetConstructorWithReflectionPermission
      (Type type, Type baseType, Boolean throwOnError)
at System.Configuration.MgmtConfigurationRecord.CreateSectionGroupFactory
      (FactoryRecord factoryRecord)
at System.Configuration.MgmtConfigurationRecord.EnsureSectionGroupFactory
      (FactoryRecord factoryRecord)
at System.Configuration.MgmtConfigurationRecord.GetSectionGroup
      (String configKey)
at System.Configuration.ConfigurationSectionGroupCollection.Get
      (String name)
at System.Configuration.ConfigurationSectionGroupCollection.
      <GetEnumerator>d__0.MoveNext()
at System.Configuration.Configuration.ForceGroupsRecursive
      (ConfigurationSectionGroup group)
at System.Configuration.Configuration.SaveAsImpl
      (String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
at System.Configuration.Configuration.Save
      (ConfigurationSaveMode saveMode, Boolean forceSaveAll)
at MyCompany.MyProduct.blah.blah.Save
      () in C:\\projects\\blah\\blah\\blah.cs:line blah

参考までに構成はこんな感じ

<configuration>
  <configSections>
    ... normal sections here that work just fine, followed by ...

    <sectionGroup name="threadSettings" type="System.Configuration.NameValueSectionHandler">
      <section name="T1" type="System.Configuration.DictionarySectionHandler"/>
      <section name="T2" type="System.Configuration.DictionarySectionHandler"/>
      <section name="T3" type="System.Configuration.DictionarySectionHandler"/>
    </sectionGroup>
  </configSections>
  <applicationSettings />
  <threadSettings>
    <T1>
      <add key="key-here" value="value-here"/>
    </T1>
    ... T2 and T3 here as well, thats not interesting ...
  </threadSettings>
</configuration>

実際のセクションとカスタム セクション グループの定義を削除すると、設定を正常に読み書きでき、正常に呼び出すことさえできますSave

明らかに、カスタムセクション グループはもう少し適切に設定できますが、それを修正することはできませConfigurationNameValueSectionHandler

4

0 に答える 0