Load existing assemblies by name

This commit is contained in:
Chris Cameron
2017-07-31 17:11:56 -04:00
parent e7d1b6ec83
commit 09f6b752a8
2 changed files with 24 additions and 5 deletions

View File

@@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Crestron.SimplSharp.Reflection; using Crestron.SimplSharp.Reflection;
namespace ICD.Common.Utils.Extensions namespace ICD.Common.Utils.Extensions

View File

@@ -2,7 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ICD.Common.Properties; using ICD.Common.Properties;
using ICD.Common.Utils.IO;
#if SIMPLSHARP #if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Reflection; using Crestron.SimplSharp.Reflection;
using Activator = Crestron.SimplSharp.Reflection.Activator; using Activator = Crestron.SimplSharp.Reflection.Activator;
#else #else
@@ -234,11 +236,29 @@ namespace ICD.Common.Utils
/// <returns></returns> /// <returns></returns>
public static Assembly LoadAssemblyFromPath(string path) public static Assembly LoadAssemblyFromPath(string path)
{ {
#if SIMPLSHARP if (path == null)
return Assembly.LoadFrom(path); throw new ArgumentNullException("path");
#else
string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(path);
if (string.IsNullOrEmpty(path))
throw new ArgumentException("Path is empty", "path");
string fileNameWithOutExtension = IcdPath.GetFileNameWithoutExtension(path);
#if SIMPLSHARP
try
{
return Assembly.Load(new AssemblyName {Name = fileNameWithOutExtension});
}
catch (IOException)
{
return Assembly.LoadFrom(path);
}
catch (FileNotFoundException)
{
return Assembly.LoadFrom(path);
}
#else
bool inCompileLibraries = DependencyContext.Default.CompileLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase)); bool inCompileLibraries = DependencyContext.Default.CompileLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));
bool inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase)); bool inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));