From a8eda142606cb0066411987132aa3fe2c6701911 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 21 Sep 2020 15:44:14 +1000 Subject: [PATCH] update dependency resolver to cater for existing dependency in Plugin if the assembly already referenced in Flow.Launcher.Plugin then ignore it --- .../Plugin/PluginAssemblyLoader.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs index 5bbcd1158..b9b878a7b 100644 --- a/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs @@ -1,4 +1,5 @@ -using System; +using Flow.Launcher.Infrastructure; +using System; using System.IO; using System.Linq; using System.Reflection; @@ -10,12 +11,17 @@ namespace Flow.Launcher.Core.Plugin { private readonly AssemblyDependencyResolver dependencyResolver; + private readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver; + private readonly AssemblyName assemblyName; internal PluginAssemblyLoader(string assemblyFilePath) { dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath); assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath)); + + referencedPluginPackageDependencyResolver = + new AssemblyDependencyResolver(Path.Combine(Constant.ProgramDirectory, "Flow.Launcher.Plugin.dll")); } internal Assembly LoadAssemblyAndDependencies() @@ -27,12 +33,13 @@ namespace Flow.Launcher.Core.Plugin { string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName); - if (assemblyPath != null) - { - return LoadFromAssemblyPath(assemblyPath); - } - - return null; + // When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher.Plugin + // Otherwise will get unexpected behaviour with plugins, e.g. JsonIgnore attribute not honored in WebSearch or other plugins + // that use Newtonsoft.Json + if (assemblyPath == null || ExistsInReferencedPluginPackage(assemblyName)) + return null; + + return LoadFromAssemblyPath(assemblyPath); } internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type) @@ -41,5 +48,10 @@ namespace Flow.Launcher.Core.Plugin return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(type)); } + + internal bool ExistsInReferencedPluginPackage(AssemblyName assemblyName) + { + return referencedPluginPackageDependencyResolver.ResolveAssemblyToPath(assemblyName) != null; + } } }