tags:

views:

771

answers:

3

I want to call a C# component from an unmanaged c++ service. I need to set config items expected by the C# component. What name should be config be and where should it be located.

eg. parentfolder\cplusplusservice.exe

anotherfolder\csharp.dll

i need csharp.dll.config or its equivalent.

Thanks,

A: 

This article shows how to use Configuration files with c#:

http://www.devasp.net/net/articles/display/679.html

This article provides an overview of calling managed c# component from unmanaged c++ and vice versa, as well as some helper classes:

http://www.codeproject.com/KB/mcpp/unmanaged_to_managed.aspx

Robert Harvey
A: 

The .config file needs to be named the same as the application's name. When the unmanaged code first calls into the managed code an AppDomain is created that AppDomain controls which config file is loaded and from where.

You will need to manually copy the .config file to the output directory and name it after the application name or create a post-build to do so.

Basically the same rules that apply to where .config files need to be for pure managed apps apply to unmanaged apps that load managed code.

Justin Pfifer
A: 

It depends on how the AppDomain that is hosting your managed code is created.

For example, if you are exposing the managed code as COM, it will be loaded into the default AppDomain, and the configuration file will be in the same directory as the executable (parentfolder\cplusplusservice.exe.config in your case).

If you are creating the AppDomain yourself, you can control where the configuration file is located.

Joe