By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,825 Members | 2,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,825 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Configur ationFile" 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ť

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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);
-------------
public class UFSStatusAccessDomain : MarshalByRefObject
{ ....}

"Josť Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message
news:e2**************@TK2MSFTNGP09.phx.gbl...
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.Configur ationFile" 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ť


Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.