There are two same .dll but different version in different folder. How can I force the program to refer the version I want?

Daniel_ngai 1 Reputation point
2021-03-05T07:56:09.167+00:00

I am making a plugin for a application. I installed latest version of AWS.S3 (Amazon Cloud) from NuGet. It successfully includes in the \bin\AWSSDK.S3.dll.

However, the application already has a same .dll file in the its root folder (C:\Program Files\Application\AWSSDK.S3.dll) which is in older version.
And the program shows error as my code have to run in newer version. How can I force my plugin to load the dll from assembly folder instead of root folder?

Thanks a lot

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,486 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,646 Reputation points
    2021-03-08T06:22:23.91+00:00

    Hi Danielngai-6932,
    You can add a probing path to your application's .config file, and it will only work if the probing path is a contained within your application's base directory.

    <configuration>  
        <runtime>  
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
                <probing privatePath="bin;bin2\subbin;bin3"/>  
            </assemblyBinding>  
        </runtime>  
    </configuration>  
    

    You can also use the AppDomain.AssemblyResolve event and manually load the dependencies from your DLL directory.
    More details you can refer to the following threads.
    How to add folder to assembly search path at runtime in .NET?
    c# Class Library Project - Load DLL from same folder?
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.