bool LoadExternalDependencies()
{
bool result = true;
if(_externalDependencies != null && _externalDependencies.Length > 0)
{
foreach(AssemblyReference currentReference in _externalDependencies)
{
if(result)
{
Assembly asm = null;
if(currentReference.IsGlobalAssemblyCache)
{
GAC.RebuildGACAssemblyCache(false);
string gacName = GAC.TryResolveGACAssembly(currentReference.Name, currentReference.Culture, currentReference.Version, currentReference.PublicKeyToken);
if(gacName == null)
if(GAC.RebuildGACAssemblyCache(true))
gacName = GAC.TryResolveGACAssembly(currentReference.Name, currentReference.Culture, currentReference.Version, currentReference.PublicKeyToken);
if(gacName != null)
{
try
{
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if(LogTraceInfo)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
#pragma warning disable 162
{
WriteLine("Loading External Dependencies [ " + gacName + " ]");
}
#pragma warning restore 162
// ReSharper restore HeuristicUnreachableCode
asm = Assembly.Load(gacName);
}
catch(Exception e)
{
asm = null;
Fail("External assembly \"" + gacName + "\" failed to load from global assembly cache", e);
result = false;
}
}
if(asm == null && result)
{
Fail("External assembly \"" + gacName + "\" failed to load from global assembly cache");
result = false;
}
}
else
{
string fullPath = Path.Combine(currentReference.Path, currentReference.Name.EndsWith(".dll") ? currentReference.Name : currentReference.Name + ".dll");
if(File.Exists(fullPath))
{
try
{
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if(LogTraceInfo)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
#pragma warning disable 162
{
WriteLine("Loading [ " + currentReference.Name + " ]");
}
#pragma warning restore 162
// ReSharper restore HeuristicUnreachableCode
asm = Assembly.LoadFrom(fullPath);
}
catch(Exception e)
{
asm = null;
Fail("External assembly failed to load from \"" + fullPath + "\"", e);
result = false;
}
}
if(asm == null && result)
{
Fail("External assembly failed to load from \"" + fullPath + "\"");
result = false;
}
}
if(result)
{
AppDomain.CurrentDomain.Load(asm.GetName());
}
}
}
}
return result;
}