public static Assembly AssemblyResolve(Assembly executingAssembly, ResolveEventArgs args)
{
Log.IsNull("Requesting asembly ", args.RequestingAssembly);
if (args.RequestingAssembly == null || String.IsNullOrEmpty(args.RequestingAssembly.Location))
{
return null;
}
Log.Debug("RequestingAssembly: [" + args.RequestingAssembly.Location + "], Name:[" + args.Name + "]");
var requestingAssemblyDir = Path.GetDirectoryName(args.RequestingAssembly.Location);
Log.Debug("RequestingAssembly directory is " + requestingAssemblyDir);
var assemblyName = new AssemblyName(args.Name).Name;
string assemblyPath = requestingAssemblyDir + "\\" + assemblyName + ".dll";
if (!File.Exists(assemblyPath))
{
assemblyPath = requestingAssemblyDir + "\\" + _cultureName + "\\" + assemblyName + ".dll";
if (!File.Exists(assemblyPath))
{
assemblyPath = requestingAssemblyDir + "\\" + _parentCultureName + "\\" + assemblyName + ".dll";
}
}
Log.Debug("Resolved assembly location: " + assemblyPath);
Assembly retVal = null;
try
{
if (!String.IsNullOrEmpty(assemblyPath))
{
Log.Debug("LoadFrom " + assemblyPath);
retVal = Assembly.LoadFrom(assemblyPath);
}
else
{
Log.Debug("Could not find assembly " + args.RequestingAssembly.Location);
}
}
catch (FileNotFoundException fnf)
{
Log.Exception(fnf);
if (!assemblyPath.ToLower().Contains(".resources"))
{
throw;
}
return null;
}
catch (Exception ex)
{
Log.Debug("Could not load assembly.. Exception: " + ex);
}
Log.IsNull("retVal: ", retVal);
return retVal;
}