views:

146

answers:

2

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?

A: 

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?

Martin Smith
Having trouble getting filtering to work. Just noticed that a "Debug" folder has appeared under the solution, containing the ClientConsole.exe, and there are no .config's in that folder. Also, the C# component, Bridge.dll is not in that folder, so I guess thanks to it's registration in the Registry COM is able to locate and load it.
IanT8
Outside of Visual Studio, it needs a ClientConsole.exe.config. Still investigating...
IanT8
RE: Filtering not sure if this is the issue you are having or if it's just me but I repeatedly forget with procmon that I need to click "Add" then "OK" in the Filter dialogue box rather than just "OK"!
Martin Smith
The default behavior of a C++ project in VS2008 is for the linker to produce the build output in a folder named Debug or Release outside the project folder under the solution! I didn't know that and although I had a ClientConsole.exe.config file, it was in the wrong place. As soon as a I manually copied to (solution-dir)/Debug, everthing worked. I've now added a custom build step to the c++ project to copy the config file to the same place as the target exe.
IanT8
A: 

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.

tommieb75