繁体   English   中英

COM +组件未从静态上下文读取配置

[英]COM+ component not reading configuration from static context

我有2个用C#内置的COM +应用程序。 他们需要访问配置,因此为了获得它们(由于它们在服务器上下文中),我将COM +应用程序中的“应用程序根目录”设置为包含application.manifest和application.config文件的目录。 我以此方式构建的第一个组件起作用。 第二个组件,我找不到与我编写方式相同的有意义的区别。

如果您尝试从静态上下文使用ConfigurationManager.GetSection("unity")访问配置,则它将返回null。 从非静态上下文中调用同一事物会产生预期的结果(返回此部分)。 由于第一个组件可以从静态上下文正确调用它,所以我在做什么错呢?

在DLL 1中有效,但在DLL 2中无效:

private static IUnityContainer m_unityContainer = new UnityContainer().LoadConfiguration()

在DLL 2中工作:

private IUnityContainer m_unityContainer = new UnityContainer().LoadConfiguration()

要么

private IUnityContainer m_unityContainer; public void Process() { m_unityContainer = new UnityContainer().LoadConfiguration(); }

在读取我的COM +程序集中的配置文件时遇到了类似的问题。

对我有用的是:

1)application.config文件和application.manifest都需要与程序集位于同一文件夹(在我的情况下为debug文件夹)。

2)需要在COM +应用程序的“激活”选项卡中指定应用程序根目录。 运行组件服务,右键单击“属性”,转到“激活”选项卡。 也可以使用regsvcs / appdir:选项执行此操作。

我不确定,但是我认为这与x64和x86的差异有关。 我通过将代码更改为来解决了

private static readonly Lazy<IUnityContainer> m_unityContainer = new Lazy<IUnityContainer>(() => new UnityContainer().LoadConfiguration());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM