Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load assemblies outside the appbase(more information)

Tags:

c#

.net

I want to know how to load assemblies which are outside the Appbase and Appdomain.

My problem is that I have a list of assemblies that are on a shared directory. My application needs to load these assemblies, which are located outside the path specified in the Appbase (path to the executable). I do not want to move them into the Appbase folder.

For more information, I have an application which is running in a distributed domain to test a collection of assemblies. When the application starts, it loads these assemblies from an array. When I test this application on my local desktop, it works well (loads and make reflection from assemblies, etc.), but from the cluster computers, it can't load those same assemblies, and throws the following Exception:

FileNotFoundException. Could not load file or assembly or one of its dependencies. The system cannot find the file specified.

like image 567
Bordel Bordel Avatar asked Jan 19 '23 05:01

Bordel Bordel


1 Answers

There is an event that is fired if it can't find an assembly or one of its references:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {

        }

Add it before you're loading your assemblies. Put a breakpoint in it and in args there should be some info about the assembly you're missing

like image 77
hcb Avatar answered Apr 01 '23 15:04

hcb