I would like to load assemblies from a folder that is not my current app domain base folder. Some of the assemblies that I would like to load are already loaded in an older version in default app domain. In order to run this I found the following code. The new loaded assemblies are located in folder c:\testa\
How to Load an Assembly to AppDomain with all references recursively?
class Program
{
static void Main(string[] args)
{
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = @"c:\testa\";
Evidence adevidence = AppDomain.CurrentDomain.Evidence;
AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence, domaininfo);
Type type = typeof(Proxy);
var value = (Proxy)domain.CreateInstanceAndUnwrap(
type.Assembly.FullName,
type.FullName);
var assembly = value.GetAssembly(args[0]);
// AppDomain.Unload(domain);
}
}
public class Proxy : MarshalByRefObject
{
public Assembly GetAssembly(string assemblyPath)
{
try
{
return Assembly.LoadFile(assemblyPath);
}
catch (Exception)
{
return null;
// throw new InvalidOperationException(ex);
}
}
}
As the author of the code mentioned I get a file or dependency not found. So how can I handle this problem. Any idea?