C #: specifying location for a Dll reference

In a C # console application, we can add a link to the dll in [Soln Explorer - Links and then add a link to the reqd dll].

In this case, the application expects the dll to be present in the same folder. if not, then the application does not work [Throws an exception].

Is it possible that if the dll is not present in the same folder as in the [exe] application then we have another alternative location \ path from which the program can load the dll reqd and then continue its functionality.

Thanks, Amit

+2


source to share


4 answers


As pointed out by Fredik , you can install the assembly in the GAC. There is another way to do this. You can copy the assembly to any location (make this location reliable if it is online) and handle the ModuleResolve event of type Assembly. In the callback, you have a chance to resolve the assembly reference.




The second time I would suggest you look at AssemblyResolver . It should definitely resolve any issues that come with resolving assemblies.

+4


source


You can add the App.config file to your application and specify the build location:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly> 
            <assemblyIdentity 
                name="MyAssembly" 
                culture="" 
                publicKeyToken="8968ee41e78ce97a" /> 
            <codeBase 
                version="1.0.0.0" 
                href="file://c:/some_path/myassembly.dll" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

      




EDIT:

  • Maybe you need to set culture = "neutral"
  • Make sure the token is correct if the assembly is strongly signed, otherwise publicKeyToken = "null"
+4


source


You can install the library to the GAC (Global Assembly Cache).

0


source


You can put all the DLLs you want to link into the Libraries folder or some of them and link to them.

Project> Links> Overview

Kindness,

Dan

0


source







All Articles