C# COM 组件加载到非托管 C++ 时无法读取配置应用程序

发布于 2024-08-23 22:27:46 字数 610 浏览 4 评论 0原文

我有一个用 C# 编写的 COM 组件,它调用 ConfigurationManager.AppSettings.Get(...)。该组件在非托管 C++ 应用程序内实例化。

每次,ConfigurationManager.AppSettings 都无法读取配置文件。

可能有两个问题。

1)应用程序运行时app.config应该被调用什么(即以.config结尾的C++ exe的名称,或者以.config结尾的我的C#类库的名称)。

2)配置文件应该放在哪里(即与 C# COM 组件位于同一文件夹中,或与 C++ exe 在同一文件夹中)

我尝试了对 ConfigurationManager.OpenExecConfiguration 的各种调用;都失败了。

理想情况下,我想要的是如果做不到这一点,请明智地调用 OpenExeConfiguration,以便我仍然可以使用 ConfigurationManager.AppSettings.Get(...)

这可能只是冰山一角,因为我想在中使用 log4net使用自定义配置部分的 C# COM 组件

虽然我不介意更改自己的代码以通过配置对象使用访问设置,但我

之前无法更改 log4net 代码。

I have a COM component written in C# that makes calls to ConfigurationManager.AppSettings.Get(...). This component is instantiated inside an unmanaged C++ application.

Every time, ConfigurationManager.AppSettings is unable to read the configuration file.

There might be two problems.

1) What should the app.config be called when the app is running (i.e. the name of the C++ exe with .config on the end, or the name of my C# class library with .config on the end).

2) Where should the config file live (i.e. in the same folder as the C# COM Component, or in the same folder as the C++ exe

I've tried various calls to ConfigurationManager.OpenExecConfiguration; all failed.

What I want ideally, is for it to just work with no code changes. Failing that, a judicious call of OpenExeConfiguration so that I can still use ConfigurationManager.AppSettings.Get(...)

This might be the tip of the iceberg because I'd like to use log4net in the C# COM Component which uses a custom config section.

Whilst I dont mind changing my own code to use access settings via a config object, I can't change the log4net code.

Anyone else hit this before? Any ideas?

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

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

发布评论

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

评论(2

捂风挽笑 2024-08-30 22:27:46

如果您运行 procmon ( http://technet.microsoft.com/en-us /sysinternals/bb896645.aspx )当您的应用程序运行时,您能看到它正在查找的 *.config 文件吗?

If you run procmon ( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx ) while your app is running can you see the *.config file that it is looking for?

丿*梦醉红颜 2024-08-30 22:27:46

通常,配置文件与 C# 二进制文件所在的位置相同......当您在包含 app.config 的项目上运行构建时,该配置文件会转换为 app.exe.config,其中 app 是名称项目解决方案的文件,以及由 .NET 框架加载和执行的 .EXE 文件,都会从 .EXE 所在的同一目录中读取配置文件。

Usually, the config file is in the same place as where the C# binary is located....when you run a build on the project that contains the app.config, that gets converted to app.exe.config where app is the name of the project solution, and hence the .EXE file when loaded and executed by the .NET framework, reads the config file from the same directory where the .EXE reside in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文