Ok, here what needs to be done to force dll to look for referenced dll in the same forlder in the case described above:
public static class GlobalKeeper
{
public static string assemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
public static Assembly assemblyResolveHandler(object sender, ResolveEventArgs args)
{
string assemblyPath = assemblyDirectory;
string[] words = args.Name.Split(',');
if (words.Length > 0)
assemblyPath += "\\" + words[0] + ".dll";
return Assembly.LoadFrom(assemblyPath);
}
public static void initialize()
{
AppDomain.CurrentDomain.AssemblyResolve += assemblyResolveHandler;
}
}