app.config setting for Component object in c#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In normal application the set and get of appSettings are simply as following

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Log" value="1" />
</appSettings>
</configuration>

string log = System.Configuration.ConfigurationSettings.AppSettings["Log"];

However, the same setting in my C#'s COM object doesn't work at all and keeps on returning "null" value.

Any comment ? Please help
 
What exe is your COM object loaded into (assuming its an in-proc object)
& what is the name of your config file?

..config files are associated with an exe so if your object is loaded into Excel then the framework is looking for excel.exe.config . Which is possibly not a palatable solution.

The built-in config mechansim isn't that useful if you don't control the .exe (technically the appdomain) that your are loaded into.

Niroo
 
Correct. .config files are associated with an exe. So if you have a MyComComponent.dll you can't supply just a .config file for it.

The approach that I would go with is to figure out where your code loads using

string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

and then manually open a file path + ".config" and use one of the XmlTextReader to read the data out.

The disadvantage is that you do need FileIO permissions, which you don't need for the normal .config file

Niroo

Maverick said:
That means if i'm creating a pure COM object module using C# (without any main() or exe associated). That's no way i can use a config file to store the configuration data, right ?


Niroo said:
What exe is your COM object loaded into (assuming its an in-proc object)
& what is the name of your config file?

.config files are associated with an exe so if your object is loaded into Excel then the framework is looking for excel.exe.config . Which is possibly not a palatable solution.

The built-in config mechansim isn't that useful if you don't control the .exe (technically the appdomain) that your are loaded into.

Niroo

Maverick said:
In normal application the set and get of appSettings are simply as following

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Log" value="1" />
</appSettings>
</configuration>

string log = System.Configuration.ConfigurationSettings.AppSettings["Log"];

However, the same setting in my C#'s COM object doesn't work at all and keeps on returning "null" value.

Any comment ? Please help
 
Back
Top