mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix Shared Assembly Issue
This commit is contained in:
parent
16e032ea55
commit
3637961513
1 changed files with 8 additions and 28 deletions
|
|
@ -11,46 +11,31 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
internal class PluginAssemblyLoader : AssemblyLoadContext
|
||||
{
|
||||
private readonly AssemblyDependencyResolver dependencyResolver;
|
||||
private readonly AssemblyDependencyResolver _dependencyResolver;
|
||||
|
||||
private readonly AssemblyName assemblyName;
|
||||
|
||||
private static readonly ConcurrentDictionary<string, byte> loadedAssembly;
|
||||
|
||||
static PluginAssemblyLoader()
|
||||
{
|
||||
var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
loadedAssembly = new ConcurrentDictionary<string, byte>(
|
||||
currentAssemblies.Select(x => new KeyValuePair<string, byte>(x.FullName, default)));
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
|
||||
{
|
||||
loadedAssembly[args.LoadedAssembly.FullName] = default;
|
||||
};
|
||||
}
|
||||
private readonly AssemblyName _assemblyName;
|
||||
|
||||
internal PluginAssemblyLoader(string assemblyFilePath)
|
||||
{
|
||||
dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath);
|
||||
assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath));
|
||||
_dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath);
|
||||
_assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath));
|
||||
}
|
||||
|
||||
internal Assembly LoadAssemblyAndDependencies()
|
||||
{
|
||||
return LoadFromAssemblyName(assemblyName);
|
||||
return LoadFromAssemblyName(_assemblyName);
|
||||
}
|
||||
|
||||
protected override Assembly Load(AssemblyName assemblyName)
|
||||
{
|
||||
string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName);
|
||||
string assemblyPath = _dependencyResolver.ResolveAssemblyToPath(assemblyName);
|
||||
|
||||
// When resolving dependencies, ignore assembly depenedencies that already exits with Flow.Launcher
|
||||
// Otherwise duplicate assembly will be loaded and some weird behavior will occur, such as WinRT.Runtime.dll
|
||||
// will fail due to loading multiple versions in process, each with their own static instance of registration state
|
||||
if (assemblyPath == null || ExistsInReferencedPackage(assemblyName))
|
||||
return null;
|
||||
var existAssembly = Default.Assemblies.FirstOrDefault(x => x.FullName == assemblyName.FullName);
|
||||
|
||||
return LoadFromAssemblyPath(assemblyPath);
|
||||
return existAssembly ?? (assemblyPath == null ? null : LoadFromAssemblyPath(assemblyPath));
|
||||
}
|
||||
|
||||
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
|
||||
|
|
@ -58,10 +43,5 @@ namespace Flow.Launcher.Core.Plugin
|
|||
var allTypes = assembly.ExportedTypes;
|
||||
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Any(t => t == type));
|
||||
}
|
||||
|
||||
internal bool ExistsInReferencedPackage(AssemblyName assemblyName)
|
||||
{
|
||||
return loadedAssembly.ContainsKey(assemblyName.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue