views:

44

answers:

1

I have a .NET assembly (.dll) that gets loaded as a COM server into an existing process. How can I get a .config file applied to it such that ConfigurationManager.GetSection will return the section out of the applied .config file?

A: 

You'll want to use ConfigurationManager.OpenMappedExeConfiguration. There's good code samples in the link, so I won't copy them here.

Harper Shelby
That just opens up a read/write copy of the .config file for authoring. It doesn't actually apply the .config file to the process such that ConfigurationManager.AppSettings or GetSection reads from that file.
Andrew Arnott
Nope - it actually forces the application to use the new configuration file. Notice the section near the bottom of the example, where RefreshSection() is called after the changes are made - it's illustrating explicitly that the ConfigurationManager is now pulling data from the mapped configuration file.
Harper Shelby