.NET dll config file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Suresh Gladstone

    .NET dll config file

    Hi,
    This is a bit with versioning and installation of
    the .NET dlls. I want to perform the following, [THIS IS
    WITH REFERENCE TO WINDOWS APPLICATION]
    1. A third party application will be invoking my .NET dll
    through COM interop . For this I have used Regasm and
    registered the assembly in the registry with CODEBASE
    option.

    eg: regasm myDll.dll
    /tlb:myDll.tlb /codebase

    2.The main dll which is invoked from the third party
    application has some other .NET dll references.
    These .NET references are common dlls used by many other
    similar main dlls. The situation is we had placed this
    common dlls in the GAC and it worked fine through
    reference.Now we have a business decision to move these
    common dll's to a local directory in the users machine
    and refer it from there. I have written a Configuration
    file and set the <codeBase ...> to point to the
    directory. But it is not working. Can anyone send me a
    sample config file how it should be. The point of concern
    here is , the configuration file should be created for
    the Dll and not the Exe.

    3. Process Eg:
    i. I have a third party application say A ,
    ii. I have a set of main assemblies say B,C,D each of
    which will be independently invoked by the third party
    application A
    iii. I have a set of common .NET dll libraries say X,Y,Z
    these will be used by the main assemblies B,C and D
    Process
    The application A will invoke main assembly B (which is
    registered in the registry with codebase option) . I have
    placed assembly B in a directory say "c:\MainDll s"
    The assembly B references X,Y,Z . I want to place these
    X,Y,Z dlls in a common directory (not in GAC)
    say "C:\CommonD lls" . The other main assemblies C and D
    will also use these common libraries from the same
    directory.


    |---------X
    A --------------->B|---------Y
    (Third party |---------Z
    application)

    I have the following question
    1.How should be the config file written in this case.Its
    for a .NET dll (not .NET exe)
    2.Where should the config file be placed. Since its a
    third party invokingapplica tion, not sure where to place
    the config file.

    Any help will be really appreciated.

    Regards,
    Suresh Gladstone








  • Yang Lu

    #2
    RE: .NET dll config file

    Suresh,

    I hope this article can help you:


    "Suresh Gladstone" wrote:
    [color=blue]
    > Hi,
    > This is a bit with versioning and installation of
    > the .NET dlls. I want to perform the following, [THIS IS
    > WITH REFERENCE TO WINDOWS APPLICATION]
    > 1. A third party application will be invoking my .NET dll
    > through COM interop . For this I have used Regasm and
    > registered the assembly in the registry with CODEBASE
    > option.
    >
    > eg: regasm myDll.dll
    > /tlb:myDll.tlb /codebase
    >
    > 2.The main dll which is invoked from the third party
    > application has some other .NET dll references.
    > These .NET references are common dlls used by many other
    > similar main dlls. The situation is we had placed this
    > common dlls in the GAC and it worked fine through
    > reference.Now we have a business decision to move these
    > common dll's to a local directory in the users machine
    > and refer it from there. I have written a Configuration
    > file and set the <codeBase ...> to point to the
    > directory. But it is not working. Can anyone send me a
    > sample config file how it should be. The point of concern
    > here is , the configuration file should be created for
    > the Dll and not the Exe.
    >
    > 3. Process Eg:
    > i. I have a third party application say A ,
    > ii. I have a set of main assemblies say B,C,D each of
    > which will be independently invoked by the third party
    > application A
    > iii. I have a set of common .NET dll libraries say X,Y,Z
    > these will be used by the main assemblies B,C and D
    > Process
    > The application A will invoke main assembly B (which is
    > registered in the registry with codebase option) . I have
    > placed assembly B in a directory say "c:\MainDll s"
    > The assembly B references X,Y,Z . I want to place these
    > X,Y,Z dlls in a common directory (not in GAC)
    > say "C:\CommonD lls" . The other main assemblies C and D
    > will also use these common libraries from the same
    > directory.
    >
    >
    > |---------X
    > A --------------->B|---------Y
    > (Third party |---------Z
    > application)
    >
    > I have the following question
    > 1.How should be the config file written in this case.Its
    > for a .NET dll (not .NET exe)
    > 2.Where should the config file be placed. Since its a
    > third party invokingapplica tion, not sure where to place
    > the config file.
    >
    > Any help will be really appreciated.
    >
    > Regards,
    > Suresh Gladstone
    >
    >
    >
    >
    >
    >
    >
    >
    >[/color]

    Comment

    • José Joye

      #3
      Re: .NET dll config file

      Regarding the usage of a config file for a dll:

      Currently, the config file is really bound to the exe file. I mean that it
      should have the same name and must normally be located in the exe file
      directory.

      Now, if you want to dedicate a given config file to a dll (and not share the
      one of the exe file which initially loaded your dll), you have to create a
      new application domain and load the dll in this application domain. This
      will give you a chance to specify the config file the application domain
      will use.

      However, you should note that classes that will be referenced on the second
      appdomain from the main appdomain should derive from "MarshalByRefOb ject"
      and they should override the "InitializeLife timeService" if you plan to have
      a long living instance (eg more than 3-4 minutes) referenced from the main
      appdomain.

      Hope this help,
      José



      Here is a snippet of how to load a dll in another domain:

      //
      // Need to isolate the assembly in a new AppDomain in order to be able to
      use a customed
      // config file [.dll.config]
      //
      //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
      // also define an assembly resolver routine in case the CLR cannot find
      our assemblies.
      AppDomain.Curre ntDomain.Assemb lyResolve+=new ResolveEventHan dler(
      this.MyResolveH andler);

      Object o = gAppDomain.Crea teInstanceAndUn wrap(
      Assembly.GetExe cutingAssembly( ).FullName,
      typeof(UFSStatu sAccessDomain). FullName);
      gUFSStatusAcces sDomain = (UFSStatusProvi der.UFSStatusAc cessDomain)o;

      // call the init on the other AppDomain
      return gUFSStatusAcces sDomain.Init(nT estLevel, out strErrDescr);

      .......

      //-----------------------------------------------------------------------------------------
      /// <summary>
      /// This method is used to provide assembly location resolver. It is
      called on event as needed by the CLR.
      /// Refer to document related to AppDomain.Curre ntDomain.Assemb lyResolve
      /// </summary>
      private Assembly MyResolveHandle r(object sender,ResolveE ventArgs e)
      {
      string[] file = e.Name.Split( ',' );
      string strDir =
      Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().Locati on);
      Assembly a = Assembly.LoadFr om( strDir + @"\" + file[0] + ".dll" );
      return a;
      }


      "Suresh Gladstone" <suresh_glad@ya hoo.com> wrote in message
      news:3aa301c4a5 75$abefe980$a30 1280a@phx.gbl.. .[color=blue]
      > Hi,
      > This is a bit with versioning and installation of
      > the .NET dlls. I want to perform the following, [THIS IS
      > WITH REFERENCE TO WINDOWS APPLICATION]
      > 1. A third party application will be invoking my .NET dll
      > through COM interop . For this I have used Regasm and
      > registered the assembly in the registry with CODEBASE
      > option.
      >
      > eg: regasm myDll.dll
      > /tlb:myDll.tlb /codebase
      >
      > 2.The main dll which is invoked from the third party
      > application has some other .NET dll references.
      > These .NET references are common dlls used by many other
      > similar main dlls. The situation is we had placed this
      > common dlls in the GAC and it worked fine through
      > reference.Now we have a business decision to move these
      > common dll's to a local directory in the users machine
      > and refer it from there. I have written a Configuration
      > file and set the <codeBase ...> to point to the
      > directory. But it is not working. Can anyone send me a
      > sample config file how it should be. The point of concern
      > here is , the configuration file should be created for
      > the Dll and not the Exe.
      >
      > 3. Process Eg:
      > i. I have a third party application say A ,
      > ii. I have a set of main assemblies say B,C,D each of
      > which will be independently invoked by the third party
      > application A
      > iii. I have a set of common .NET dll libraries say X,Y,Z
      > these will be used by the main assemblies B,C and D
      > Process
      > The application A will invoke main assembly B (which is
      > registered in the registry with codebase option) . I have
      > placed assembly B in a directory say "c:\MainDll s"
      > The assembly B references X,Y,Z . I want to place these
      > X,Y,Z dlls in a common directory (not in GAC)
      > say "C:\CommonD lls" . The other main assemblies C and D
      > will also use these common libraries from the same
      > directory.
      >
      >
      > |---------X
      > A --------------->B|---------Y
      > (Third party |---------Z
      > application)
      >
      > I have the following question
      > 1.How should be the config file written in this case.Its
      > for a .NET dll (not .NET exe)
      > 2.Where should the config file be placed. Since its a
      > third party invokingapplica tion, not sure where to place
      > the config file.
      >
      > Any help will be really appreciated.
      >
      > Regards,
      > Suresh Gladstone
      >
      >
      >
      >
      >
      >
      >
      >[/color]


      Comment

      Working...