Skip to content

Commit a8eda14

Browse files
committed
update dependency resolver to cater for existing dependency in Plugin
if the assembly already referenced in Flow.Launcher.Plugin then ignore it
1 parent ef95006 commit a8eda14

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Flow.Launcher.Infrastructure;
2+
using System;
23
using System.IO;
34
using System.Linq;
45
using System.Reflection;
@@ -10,12 +11,17 @@ internal class PluginAssemblyLoader : AssemblyLoadContext
1011
{
1112
private readonly AssemblyDependencyResolver dependencyResolver;
1213

14+
private readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver;
15+
1316
private readonly AssemblyName assemblyName;
1417

1518
internal PluginAssemblyLoader(string assemblyFilePath)
1619
{
1720
dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath);
1821
assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath));
22+
23+
referencedPluginPackageDependencyResolver =
24+
new AssemblyDependencyResolver(Path.Combine(Constant.ProgramDirectory, "Flow.Launcher.Plugin.dll"));
1925
}
2026

2127
internal Assembly LoadAssemblyAndDependencies()
@@ -27,12 +33,13 @@ protected override Assembly Load(AssemblyName assemblyName)
2733
{
2834
string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName);
2935

30-
if (assemblyPath != null)
31-
{
32-
return LoadFromAssemblyPath(assemblyPath);
33-
}
34-
35-
return null;
36+
// When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher.Plugin
37+
// Otherwise will get unexpected behaviour with plugins, e.g. JsonIgnore attribute not honored in WebSearch or other plugins
38+
// that use Newtonsoft.Json
39+
if (assemblyPath == null || ExistsInReferencedPluginPackage(assemblyName))
40+
return null;
41+
42+
return LoadFromAssemblyPath(assemblyPath);
3643
}
3744

3845
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
@@ -41,5 +48,10 @@ internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
4148

4249
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(type));
4350
}
51+
52+
internal bool ExistsInReferencedPluginPackage(AssemblyName assemblyName)
53+
{
54+
return referencedPluginPackageDependencyResolver.ResolveAssemblyToPath(assemblyName) != null;
55+
}
4456
}
4557
}

0 commit comments

Comments
 (0)