update dependency resolver to cater for existing dependency in Plugin

if the assembly already referenced in Flow.Launcher.Plugin then ignore it
This commit is contained in:
Jeremy Wu 2020-09-21 15:44:14 +10:00
parent ef950063c0
commit a8eda14260

View file

@ -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;
}
}
}