ServicedComponentを実装する.NetコンポーネントをホストするCOM+サーバーがあります。
COM +サーバーは、カスタム構成セクションが定義されている構成ファイルにアクセスする必要があります。
次のコードで構成を正常にロードできます。
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"%MY_FOLDER_WITH_ALL_DLLS%\MyComServer.dll.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
// All is fine until the next line:
MyCustomSettings customSettings = (MyCustomSettings)tempConfiguration1.GetSection("customSettings");
System.InvalidCastException:タイプ「System.Configuration.DefaultSection」のオブジェクトをタイプ「MyProject.MyCustomSettings」にキャストできません
構成ファイルでカスタム構成セクションを宣言した方法は次のとおりです。
<configSections>
<section name="MyProject.MyCustomSettings" type="MyProject.MyCustomSettings, MyProject, Version=1.0.3322.1077, Culture=neutral, PublicKeyToken=176fc8b9840b0b09"/>
</configSections>
この場合は、CustomSettingsオブジェクトを期待していたため、あまり役に立たないように見えるDefaultSectionオブジェクトを実際に返します。
MyProjectには強い名前が付けられていることに注意してください。
MyProject.dllアセンブリをGACにインストールするオプションもありますが、組織上の理由から、このソリューションは魅力的ではありません。
他に何か提案はありますか?
DLLHostで実行されているプロセスから特定のアセンブリの構成ファイルからカスタム構成セクションをロードするにはどうすればよいですか?
ありがとう。