C# COM+服务器配置和自定义配置部分
我有一个COM+服务器,它托管一个实现ServicedComponent的.Net组件 COM+服务器需要访问定义了自定义配置节的配置文件 我可以使用以下代码很好地加载配置:C# COM+服务器配置和自定义配置部分,c#,configuration,com+,C#,Configuration,Com+,我有一个COM+服务器,它托管一个实现ServicedComponent的.Net组件 COM+服务器需要访问定义了自定义配置节的配置文件 我可以使用以下代码很好地加载配置: ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"%MY_FOLDER_WITH_ALL_DLLS%\MyComServer.dll.config"; Configuration co
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中运行的进程中从给定程序集的配置文件加载自定义配置节
谢谢。我自己也为这个问题浪费了几个小时。最后我通过移动到右下方解决了这个问题。在这段时间里,我有了上面提到的其他配置元素