Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to reference .net DLL present in other folder

How to reference .net DLL present in other folder

Scheduled Pinned Locked Moved C#
csharpdotnethelptutorial
16 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jschell

    KASR1 wrote:

    For some
    reason i need to move a dll to program
    files folder

    No there is no reason you need to do that. Just as many other programs do not. What they do is create a sub folder and that is where the application goes.

    K Offline
    K Offline
    KASR1
    wrote on last edited by
    #5

    I am not sure whether i have confused. Lets put that again, during deployment of my application i need install a particular dll to program files sub directory (eg. C:\program files\test). But my application will be in different directory. Since the dll Installed away from application directory and it uses/references many dlls present in application directory. How do i make that dll to pick dependent dlls from application directory. I dont want to move to GAC. Hope its clear.

    J 1 Reply Last reply
    0
    • K KASR1

      I am not sure whether i have confused. Lets put that again, during deployment of my application i need install a particular dll to program files sub directory (eg. C:\program files\test). But my application will be in different directory. Since the dll Installed away from application directory and it uses/references many dlls present in application directory. How do i make that dll to pick dependent dlls from application directory. I dont want to move to GAC. Hope its clear.

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #6

      Your application, let us call in it MyApp.exe will live in the following directly. C:\program files\MyCompany The dependent dlls will live in the same directory.

      K 1 Reply Last reply
      0
      • J jschell

        Your application, let us call in it MyApp.exe will live in the following directly. C:\program files\MyCompany The dependent dlls will live in the same directory.

        K Offline
        K Offline
        KASR1
        wrote on last edited by
        #7

        Lets us take an eg., I have MyApp.exe, Test1.dll,Test2.dll,Test3.dll. MyApp.exe depends/uses Test1.dll Test1.dll depends/uses Test2.dll, Test3.dll If i am installing all binaries to same directory say D:\TestAppln\ then my application will work perfectly. But due to some issues i need to move Test1.dll to programfiles sub-directory always(e.g, C:\program files\MyCompany) irrespective of installation. My application may reside in any directory. Since Test1.dll depends on Test2.dll and Test3.dll, i need to copy them from application folder to Test1.dll's folder i'e (e.g, C:\program files\MyCompany). Otherwise Test1.dll will not load. So my question is how to make Test1.dll to refer its dependant dll from application folder. I am looking for options other than GAC.

        J 1 Reply Last reply
        0
        • K KASR1

          I am developing an c# application and it uses many .net assemblies. For some reason i need to move a dll to program files folder and that dll depends on many other assembly present in the application folder and this makes me to copy all dependent dlls to programfiles folder. This will cause duplication of dll in both application and programfiles directory. I know that moving dependent assembly to GAC will resolve this issue but i shound not put many assembly in GAC. So please suggest a way to make .Net dll to reference its dependent dlls.

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #8

          Yes this is possible, for strongly named assemblies, with an addition to the configuration section of the application's configuration file ( appname.exe.config ). In this example we have an assembly StealthLib.dll which has been moved out of the applications's base directory to v:\Temp. Information about this new location is given in the dependentAssembly element where we must specify the assemblyIdentity and the codeBase.

          Be really careful when editing the configuration file as errors are silently ignored. For example the assembly will not be found if the casing of publicKeyToken is changed to PublicKeyToken. The Assembly Binding Log Viewer (FUSLOGVW.exe) which comes with the .NET SDK is very useful for resolving assembly loading problems as it will log all the locations that have been searched for dependent assemblies.

          LOG: Appbase = file:///E:/VC/Projects/CP/AssemblyProbing/MainProg/bin/Debug/
          LOG: Initial PrivatePath = NULL
          LOG: Dynamic Base = NULL
          LOG: Cache Base = NULL
          LOG: AppName = MainProg.exe
          Calling assembly : MainProg, Version=1.0.4743.26012, Culture=neutral, PublicKeyToken=null.

          LOG: This bind starts in default load context.
          LOG: Using application configuration file: E:\VC\Projects\CP\AssemblyProbing\MainProg\bin\Debug\MainProg.exe.config
          LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
          LOG: Post-policy reference: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
          LOG: GAC Lookup was unsuccessful.
          LOG: Attempting download of new URL file:///v:/Temp/StealthLib.dll.
          LOG: Assembly download was successful. Attempting setup of file: v:\Temp\StealthLib.dll
          LOG: Entering run-from-source setup phase.
          LOG: Assembly Name is: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
          LOG: Binding succeeds. Returns assembly from v:\Temp\StealthLib.dll.
          LOG: Assembly is loaded in default load context.

          Good luck Alan.

          K 1 Reply Last reply
          0
          • A Alan N

            Yes this is possible, for strongly named assemblies, with an addition to the configuration section of the application's configuration file ( appname.exe.config ). In this example we have an assembly StealthLib.dll which has been moved out of the applications's base directory to v:\Temp. Information about this new location is given in the dependentAssembly element where we must specify the assemblyIdentity and the codeBase.

            Be really careful when editing the configuration file as errors are silently ignored. For example the assembly will not be found if the casing of publicKeyToken is changed to PublicKeyToken. The Assembly Binding Log Viewer (FUSLOGVW.exe) which comes with the .NET SDK is very useful for resolving assembly loading problems as it will log all the locations that have been searched for dependent assemblies.

            LOG: Appbase = file:///E:/VC/Projects/CP/AssemblyProbing/MainProg/bin/Debug/
            LOG: Initial PrivatePath = NULL
            LOG: Dynamic Base = NULL
            LOG: Cache Base = NULL
            LOG: AppName = MainProg.exe
            Calling assembly : MainProg, Version=1.0.4743.26012, Culture=neutral, PublicKeyToken=null.

            LOG: This bind starts in default load context.
            LOG: Using application configuration file: E:\VC\Projects\CP\AssemblyProbing\MainProg\bin\Debug\MainProg.exe.config
            LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
            LOG: Post-policy reference: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
            LOG: GAC Lookup was unsuccessful.
            LOG: Attempting download of new URL file:///v:/Temp/StealthLib.dll.
            LOG: Assembly download was successful. Attempting setup of file: v:\Temp\StealthLib.dll
            LOG: Entering run-from-source setup phase.
            LOG: Assembly Name is: StealthLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0505f3b3553d5af
            LOG: Binding succeeds. Returns assembly from v:\Temp\StealthLib.dll.
            LOG: Assembly is loaded in default load context.

            Good luck Alan.

            K Offline
            K Offline
            KASR1
            wrote on last edited by
            #9

            Oh really great!. your input much appreciated. I have another question, Can we use the configfile for a dll to locate its dependent assembly? Or its only applicable for exe?

            A 1 Reply Last reply
            0
            • K KASR1

              Oh really great!. your input much appreciated. I have another question, Can we use the configfile for a dll to locate its dependent assembly? Or its only applicable for exe?

              A Offline
              A Offline
              Alan N
              wrote on last edited by
              #10

              That's an interesting question that I don't know the answer to. Why not try it out? I may look at it tomorrow and if I do I'll post another reply. Alan.

              K 1 Reply Last reply
              0
              • K KASR1

                Lets us take an eg., I have MyApp.exe, Test1.dll,Test2.dll,Test3.dll. MyApp.exe depends/uses Test1.dll Test1.dll depends/uses Test2.dll, Test3.dll If i am installing all binaries to same directory say D:\TestAppln\ then my application will work perfectly. But due to some issues i need to move Test1.dll to programfiles sub-directory always(e.g, C:\program files\MyCompany) irrespective of installation. My application may reside in any directory. Since Test1.dll depends on Test2.dll and Test3.dll, i need to copy them from application folder to Test1.dll's folder i'e (e.g, C:\program files\MyCompany). Otherwise Test1.dll will not load. So my question is how to make Test1.dll to refer its dependant dll from application folder. I am looking for options other than GAC.

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #11

                You can load the dlls dynamically. Also the AppDomain has an option that allows you to specify a search path. Creating an AppDomain yourself is one option. However I believe it is also possible to set that in the application itself perhaps via one of the properties.

                1 Reply Last reply
                0
                • K KASR1

                  I am developing an c# application and it uses many .net assemblies. For some reason i need to move a dll to program files folder and that dll depends on many other assembly present in the application folder and this makes me to copy all dependent dlls to programfiles folder. This will cause duplication of dll in both application and programfiles directory. I know that moving dependent assembly to GAC will resolve this issue but i shound not put many assembly in GAC. So please suggest a way to make .Net dll to reference its dependent dlls.

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #12

                  KASR1 wrote:

                  i shound not put many assembly in GAC

                  Why not?

                  K 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    KASR1 wrote:

                    i shound not put many assembly in GAC

                    Why not?

                    K Offline
                    K Offline
                    KASR1
                    wrote on last edited by
                    #13

                    Even i am concerned about that, but i was asked to find other possible options to make the dll to refer its dependent dlls. I am interested to know whether it can be achieved via config file.

                    1 Reply Last reply
                    0
                    • A Alan N

                      That's an interesting question that I don't know the answer to. Why not try it out? I may look at it tomorrow and if I do I'll post another reply. Alan.

                      K Offline
                      K Offline
                      KASR1
                      wrote on last edited by
                      #14

                      Did you get any update on this?

                      A 1 Reply Last reply
                      0
                      • K KASR1

                        Did you get any update on this?

                        A Offline
                        A Offline
                        Alan N
                        wrote on last edited by
                        #15

                        If you have say App.exe -> DllA -> DllB, i.e. DllA uses DllB and App does not directly reference DllB. If DllA and DllB have been moved out of the application base directory then App.exe.config must be edited to provide separate location information for both DllA and DllB and there is no assumption that DllB now resides in the same place as DllA. Think of it like this: There is one process and the code in DllA executes in the context of that process. When code in DllA needs to call code residing in DllB then that assembly is loaded by 'the process' whose default locations are the GAC and the application base directory. Overrides to this default behaviour are on a per assembly basis. Any information contained within *.dll.config is not read automatically and will be ignored. Alan.

                        K 1 Reply Last reply
                        0
                        • A Alan N

                          If you have say App.exe -> DllA -> DllB, i.e. DllA uses DllB and App does not directly reference DllB. If DllA and DllB have been moved out of the application base directory then App.exe.config must be edited to provide separate location information for both DllA and DllB and there is no assumption that DllB now resides in the same place as DllA. Think of it like this: There is one process and the code in DllA executes in the context of that process. When code in DllA needs to call code residing in DllB then that assembly is loaded by 'the process' whose default locations are the GAC and the application base directory. Overrides to this default behaviour are on a per assembly basis. Any information contained within *.dll.config is not read automatically and will be ignored. Alan.

                          K Offline
                          K Offline
                          KASR1
                          wrote on last edited by
                          #16

                          Thanks for the update. Immm... Need to find a way.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups