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

发布于 2024-10-13 01:31:34 字数 765 浏览 6 评论 0原文

我有 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( )

私有 IUnityContainer m_unityContainer; 公共无效进程() { m_unityContainer = new UnityContainer().LoadConfiguration(); }

I have 2 COM+ applications built in C#. They need access to a configuration, so in order to get them that (since they are in a server context) I set the Application Root Directory in the COM+ application to be a directory that contains an application.manifest and application.config file. The first component I built this way works. The second component, which I cannot find a single meaningful difference in the way I wrote it, does not.

If you try to access the configuration using ConfigurationManager.GetSection("unity") from a static context, it will return null. Calling the same thing from a non-static context produces the expected results (the section is returned). Since the first component works correctly calling that from a static context, what am I doing wrong?

Works in DLL 1, but not in DLL 2:

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

Works in DLL 2:

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

or


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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

緦唸λ蓇 2024-10-20 01:31:34

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

对我有用的:

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

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

Had a similar problem reading the config file in my COM+ assembly.

What worked for me:

1) BOTH the application.config file and application.manifest need to be in the same folder as the assembly (in my case debug folder).

2) The Application Root Directory needs to be specified in the Activation Tab of the COM+ Application. Run Component Services, right click Properties, go to Activation tab. Can also do this using regsvcs /appdir: option.

壹場煙雨 2024-10-20 01:31:34

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

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

I'm not sure, but I think this had something to do with the differences in x64 and x86. I solved it by changing the code to

private static readonly Lazy<IUnityContainer> m_unityContainer = new Lazy<IUnityContainer>(() => new UnityContainer().LoadConfiguration());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文