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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • José Joye

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

    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.Curr entDomain.Setup Information.Con figurationFile" 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
    "ConfigurationS ettings.AppSett ings[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é





  • José Joye

    #2
    Re: How to change the config file to be used by the current application?

    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(Assemb ly.GetExecuting Assembly().Loca tion);
    string appBase = fileInfo.Direct oryName;
    string configFile = fileInfo.Name + ".config";

    //set the app base and the config file
    setup.Applicati onBase = appBase;
    setup.Configura tionFile = configFile;

    //create the domain
    gAppDomain = AppDomain.Creat eDomain ("ExportedVi ew: " +
    Guid.NewGuid(). ToString(), null, setup);

    //create the type inside the domain, and get the interface to it
    gUFSStatusAcces sDomain = (UFSStatusAcces sDomain)
    gAppDomain.Crea teInstanceAndUn wrap(
    Assembly.GetExe cutingAssembly( ).FullName,
    typeof(UFSStatu sAccessDomain). FullName);


    -------------
    public class UFSStatusAccess Domain : MarshalByRefObj ect
    { ....}

    "José Joye" <jose.joye@KILL THESPAMSbluewin .ch> wrote in message
    news:e21GdrGbDH A.2296@TK2MSFTN GP09.phx.gbl...[color=blue]
    > 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[/color]
    it[color=blue]
    > from the VB client, I want to link the config file to my assembly and not[/color]
    to[color=blue]
    > the applicaction. In that sense, the config file will be called
    > <myAssemblyName >.dll.config and will be located in the same directory as[/color]
    my[color=blue]
    > assembly dll.
    >
    > I tried to use the
    > "AppDomain.Curr entDomain.Setup Information.Con figurationFile" 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
    > "ConfigurationS ettings.AppSett ings[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é
    >
    >
    >
    >
    >[/color]


    Comment

    Working...