我有一个COM +服务器托管实现ServicedComponent的.Net组件。COM +服务器配置与自定义ConfigurationSection
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>
这种情况确实返回能源部一个DefaultSection对象因为我期待着一个CustomSettings对象,所以它似乎没什么用处。
请注意MyProject是强命名的。
一个选项是在GAC中安装MyProject.dll程序集,但由于组织原因,此解决方案不具吸引力。
还有其他建议吗?
如何从DLLHost中运行的进程中加载给定程序集配置文件中的自定义配置节?
谢谢。