C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App

两盒软妹~` 提交于 2019-12-24 00:44:06

问题


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?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/2404988/c-sharp-com-component-fails-to-read-config-when-loaded-into-an-unmanaged-c-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!