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
7 1/2 years late. You can't https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/specify-assembly-location
The directories specified in privatePath must be subdirectories of the application base directory.
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
What About MSDN - Assembly Load File
string filePath = "C:\asmPath";
Assembly myAssembly = Assembly.LoadFile(filePath);
You can also define a probe path in your app.config (which I consider a better solution) and having the CLR loading the assemblies on demand. MSDN Probing Path
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
thanks to @hcb's instruction I finally solve this problem:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Dll2Find"))
{
try
{
return Assembly.LoadFrom(@"D:\findHere\Dll2Find.dll");
}
catch (Exception)
{
return null;
}
}
return null;
}