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. referencing a dll available in a different folder from a Windows Service without copying the dll

referencing a dll available in a different folder from a Windows Service without copying the dll

Scheduled Pinned Locked Moved C#
csharpjsonhelptutorialquestion
4 Posts 3 Posters 0 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.
  • G Offline
    G Offline
    govindarajan k
    wrote on last edited by
    #1

    In the C# Windows Service we develop, we need to refer a dll file from a different folder, for an API Method call of a method in the dll. This we want to accomplish by directly accessing the folder where the dll exists. Also, we do not want the dll to be copied into the folder where the Executable file of the Windows Service is available. Example, we have a windows service called IdMAccountService,with it's Executable file IdMAccountService.exe available in D:\MetraTech\RMP\BIN folder . In that service we are referencing a dll file D:\MetraTech\RMP\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll for an API Method Call. Is it possible for us to do it without copying the above dll to D:\MetraTech\RMP\BIN folder? For this, I tried setting the ‘Copy Local’ as False in the reference to the dll and tried creating the Shortcut of the DLL file in the D:\MetraTech\RMP\BIN folder. On both the cases, Service while executing gives the error as 'Error Could not load file or assembly 'MetraTech.Account.ClientProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0f5c26dbec45a75' or one of its dependencies. The system cannot find the file specified.'. I would like to know how I can make it work as expected? Please clarify.

    Thanks & Regards, Govindarajan K.

    P A 2 Replies Last reply
    0
    • G govindarajan k

      In the C# Windows Service we develop, we need to refer a dll file from a different folder, for an API Method call of a method in the dll. This we want to accomplish by directly accessing the folder where the dll exists. Also, we do not want the dll to be copied into the folder where the Executable file of the Windows Service is available. Example, we have a windows service called IdMAccountService,with it's Executable file IdMAccountService.exe available in D:\MetraTech\RMP\BIN folder . In that service we are referencing a dll file D:\MetraTech\RMP\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll for an API Method Call. Is it possible for us to do it without copying the above dll to D:\MetraTech\RMP\BIN folder? For this, I tried setting the ‘Copy Local’ as False in the reference to the dll and tried creating the Shortcut of the DLL file in the D:\MetraTech\RMP\BIN folder. On both the cases, Service while executing gives the error as 'Error Could not load file or assembly 'MetraTech.Account.ClientProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0f5c26dbec45a75' or one of its dependencies. The system cannot find the file specified.'. I would like to know how I can make it work as expected? Please clarify.

      Thanks & Regards, Govindarajan K.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You could always use the AssemblyResolve[^] event which will be triggered when it can't find the assembly in the current path.

      This space for rent

      1 Reply Last reply
      0
      • G govindarajan k

        In the C# Windows Service we develop, we need to refer a dll file from a different folder, for an API Method call of a method in the dll. This we want to accomplish by directly accessing the folder where the dll exists. Also, we do not want the dll to be copied into the folder where the Executable file of the Windows Service is available. Example, we have a windows service called IdMAccountService,with it's Executable file IdMAccountService.exe available in D:\MetraTech\RMP\BIN folder . In that service we are referencing a dll file D:\MetraTech\RMP\Extensions\Account\Bin\MetraTech.Account.ClientProxies.dll for an API Method Call. Is it possible for us to do it without copying the above dll to D:\MetraTech\RMP\BIN folder? For this, I tried setting the ‘Copy Local’ as False in the reference to the dll and tried creating the Shortcut of the DLL file in the D:\MetraTech\RMP\BIN folder. On both the cases, Service while executing gives the error as 'Error Could not load file or assembly 'MetraTech.Account.ClientProxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a0f5c26dbec45a75' or one of its dependencies. The system cannot find the file specified.'. I would like to know how I can make it work as expected? Please clarify.

        Thanks & Regards, Govindarajan K.

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

        You can specify the location of strongly named assemblies in an application configuration file. I think doing so creates a maintenance nightmare but if you want to try it here are the details. Add a application configuration file to the project and add the following

        The location of the assembly is hard coded which is less than ideal and a slight improvement is possible by specifying a relative path in the codeBase href attribute. If application base directory is D:\MetraTech\RMP\BIN then this should be correct.

        If the ClientProxies.dll relies upon other assemblies within ..\Extensions\Account\Bin then a dependentAssembly element must be added for each one otherwise the assembly loader will only look in the GAC or the application base directory. Good luck and remember that all the xml is case sensitive. If you enter PublicKeyToken instead of publicKeyToken then the loader won't complain and will just quietly ignore the whole dependentAssembly element. Alan.

        G 1 Reply Last reply
        0
        • A Alan N

          You can specify the location of strongly named assemblies in an application configuration file. I think doing so creates a maintenance nightmare but if you want to try it here are the details. Add a application configuration file to the project and add the following

          The location of the assembly is hard coded which is less than ideal and a slight improvement is possible by specifying a relative path in the codeBase href attribute. If application base directory is D:\MetraTech\RMP\BIN then this should be correct.

          If the ClientProxies.dll relies upon other assemblies within ..\Extensions\Account\Bin then a dependentAssembly element must be added for each one otherwise the assembly loader will only look in the GAC or the application base directory. Good luck and remember that all the xml is case sensitive. If you enter PublicKeyToken instead of publicKeyToken then the loader won't complain and will just quietly ignore the whole dependentAssembly element. Alan.

          G Offline
          G Offline
          govindarajan k
          wrote on last edited by
          #4

          Thanks Alan for the inputs provided. It worked fine for me.

          Govind.

          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