From 09f6b752a89b962014d8726782146f94e2891294 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 31 Jul 2017 17:11:56 -0400 Subject: [PATCH] Load existing assemblies by name --- .../Extensions/ReflectionExtensions.cs | 1 - ICD.Common.Utils/ReflectionUtils.cs | 28 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs index 777e545..c26f090 100644 --- a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs +++ b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; - using Crestron.SimplSharp.Reflection; namespace ICD.Common.Utils.Extensions diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index 4be7a4c..0a6ecb8 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Linq; using ICD.Common.Properties; +using ICD.Common.Utils.IO; #if SIMPLSHARP +using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.Reflection; using Activator = Crestron.SimplSharp.Reflection.Activator; #else @@ -234,11 +236,29 @@ namespace ICD.Common.Utils /// public static Assembly LoadAssemblyFromPath(string path) { -#if SIMPLSHARP - return Assembly.LoadFrom(path); -#else - string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(path); + if (path == null) + throw new ArgumentNullException("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 inRuntimeLibraries = DependencyContext.Default.RuntimeLibraries.Any(l => l.Name.Equals(fileNameWithOutExtension, StringComparison.OrdinalIgnoreCase));