tags:

views:

84

answers:

1

I've been working on a .NET library. Of course .NET has a good way of working with configurations, and therefore I can document to library users what they should put in their app.config.

However I've also to expose the library as a COM object, for legacy support. Some users of the library will be VB6 applications, which doesn't have a app.config concept.

I know I can "fudge" the file using OpenExeConfiguration, along with naming, but that causes me other issues.

Is there a common way to initialise your COM based library? Worst case, I can expose an initialise method, which takes all of the initialisation parameters as individual parameters, but I fear that this makes it difficult to add new initialisation parameters, as it results in breaking the API interface.

I guess I'm thinking of passing something like an Array of key, value pairs, but before I do this, is there a "standard" way that I'm not considering?

+2  A: 

Hmmm, check your assumptions.

The app.config has nothing to do with whether VB6 is used in the exe. The app.exe.config thing is a .NET convention. When .NET code is loaded into an exe, it looks in .config for config settings. It does not matter if VB6 was used to create the exe.

For example, if you build a COM component in .NET, then host it in dllhost.exe, your .NET logic will read its configuration from a file called dllhost.exe.config, located in the same dir as dllhost.exe (which is usually %windir%\system32). The fact that the dllhost.exe binary has no knowledge of the .config file is irrelevant.

Aside from that, your plan to use a key/value pair for init is good. It is easy to use, flexible, extensible. You may want to do both - the config file and the Init() method, to allow Init to override things as necessary. In many cases the .config file is accessible to admins only, and not changeable. So you may need some way to provide user-definable settings, outside of the .exe.config.

See also: How can I debug a VB6 project that has a .NET interop component?

  • answers to that question point out that when debugging, you should use vb6.exe.config for your config file, whereas when running you need app-name.exe.config .
Cheeso