1
- using System ;
1
+ using Flow . Launcher . Infrastructure ;
2
+ using System ;
2
3
using System . IO ;
3
4
using System . Linq ;
4
5
using System . Reflection ;
@@ -10,12 +11,17 @@ internal class PluginAssemblyLoader : AssemblyLoadContext
10
11
{
11
12
private readonly AssemblyDependencyResolver dependencyResolver ;
12
13
14
+ private readonly AssemblyDependencyResolver referencedPluginPackageDependencyResolver ;
15
+
13
16
private readonly AssemblyName assemblyName ;
14
17
15
18
internal PluginAssemblyLoader ( string assemblyFilePath )
16
19
{
17
20
dependencyResolver = new AssemblyDependencyResolver ( assemblyFilePath ) ;
18
21
assemblyName = new AssemblyName ( Path . GetFileNameWithoutExtension ( assemblyFilePath ) ) ;
22
+
23
+ referencedPluginPackageDependencyResolver =
24
+ new AssemblyDependencyResolver ( Path . Combine ( Constant . ProgramDirectory , "Flow.Launcher.Plugin.dll" ) ) ;
19
25
}
20
26
21
27
internal Assembly LoadAssemblyAndDependencies ( )
@@ -27,12 +33,13 @@ protected override Assembly Load(AssemblyName assemblyName)
27
33
{
28
34
string assemblyPath = dependencyResolver . ResolveAssemblyToPath ( assemblyName ) ;
29
35
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 ) ;
36
43
}
37
44
38
45
internal Type FromAssemblyGetTypeOfInterface ( Assembly assembly , Type type )
@@ -41,5 +48,10 @@ internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
41
48
42
49
return allTypes . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( type ) ) ;
43
50
}
51
+
52
+ internal bool ExistsInReferencedPluginPackage ( AssemblyName assemblyName )
53
+ {
54
+ return referencedPluginPackageDependencyResolver . ResolveAssemblyToPath ( assemblyName ) != null ;
55
+ }
44
56
}
45
57
}
0 commit comments