Is it possible to separate a C# executable and its dependent dlls in different folder and run the application ?

Sachin Jose 61 Reputation points
2022-01-25T07:04:06.273+00:00

I am working on a feasibility task, where it is required to keep a C# - WPF application in a folder and to keep its dependency dlls in a separate folder. Is it possible to do dynamic loading ?

When I investigated I found that .NET assemblies should be placed in a common directory/sub directories due to security reasons, otherwise it wont work. My requirement is to separate them in a different drive-folder.

Can you suggest a solution for this?

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | 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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Hui Liu-MSFT 48,711 Reputation points Microsoft External Staff
    2022-01-25T09:06:52.11+00:00

    Yes, you could load dependent assemblies from anywhere you like by handling the AppDomain.AssemblyResolve Event. If your application knows that the dependent assemblies may be in another directory, it can handle this event (which automatically means they can't be found in the application directory, since the .Net framework looks there first), and try to retrieve the directory load Alternate location for device assembly.

    For more information, see Resolving Assembly Loads.

    See also solutions here.


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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