How to change the config file to be used by the current application?

J

José Joye

Hello,

I have an assembly that is used by a VB6 application. This application can
be a normal exe or an ActiveX (called through CCW).
My assembly needs to get extra info from a config file. In order to hide it
from the VB client, I want to link the config file to my assembly and not to
the applicaction. In that sense, the config file will be called
<myAssemblyName>.dll.config and will be located in the same directory as my
assembly dll.

I tried to use the
"AppDomain.CurrentDomain.SetupInformation.ConfigurationFile" property to
amend the config file to be used. However, it does not work (According to
documentation: This property cannot be changed after the AppDomain has
finished its first bind)


My problem is that my assembly makes use of
"ConfigurationSettings.AppSettings[strKey]" to blindly get keys from the
configuration file and I can not really modify the part of the code that
retrieve info from the config file. Furtermore, I also use the config file
to get info about switches and listener


Is there a way to force my assembly to use a custom config file?


Thanks,
José
 
J

José Joye

I went a step further...

Using AppDomain, I was able to use another config file.
In fact, I load my class in another AppDomain for which I can specify the
config file to use and then I forward the call to the newly created class
(see code below if needed).


This work fine if the client is managed. For an unmanaged client, this works
if you place all the dlls in the same directory...
At the present, the unmanaged part must be an exe and it is not possible to
run it from the VB6 IDE.. This will make problem when
trying to probe the dll :-((


A point that is still open to me is how to debug the managed part when
client is unmanaged


José




======================

//create the config settings object
AppDomainSetup setup = new AppDomainSetup();

//work out what the config file name and app base are
FileInfo fileInfo = new
FileInfo(Assembly.GetExecutingAssembly().Location);
string appBase = fileInfo.DirectoryName;
string configFile = fileInfo.Name + ".config";

//set the app base and the config file
setup.ApplicationBase = appBase;
setup.ConfigurationFile = configFile;

//create the domain
gAppDomain = AppDomain.CreateDomain ("ExportedView: " +
Guid.NewGuid().ToString(), null, setup);

//create the type inside the domain, and get the interface to it
gUFSStatusAccessDomain = (UFSStatusAccessDomain)
gAppDomain.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName,
typeof(UFSStatusAccessDomain).FullName);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top