Skip to content

Commit

Permalink
Merge branch 'hotfix/4.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Averus-a committed Oct 12, 2021
2 parents 4ad97fb + b2cab91 commit 78a4b4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Orc.Extensibility.Tests/Orc.Extensibility.approved.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected virtual System.Threading.Tasks.Task FindPluginsInDirectoryAsync(Orc.Ex
protected virtual System.Threading.Tasks.Task FindPluginsInLoadedAssembliesAsync(Orc.Extensibility.PluginProbingContext context) { }
protected virtual System.Threading.Tasks.Task FindPluginsInUnloadedAssembliesAsync(Orc.Extensibility.PluginProbingContext context) { }
protected virtual System.Collections.Generic.List<string> FindResolvableAssemblyPaths(string assemblyPath) { }
protected virtual System.Version GetFileVersion(string fileName) { }
protected virtual System.Collections.Generic.List<Orc.Extensibility.IPluginInfo> GetOldestDuplicates(System.Collections.Generic.List<Orc.Extensibility.IPluginInfo> duplicates) { }
protected abstract bool IsPlugin(Orc.Extensibility.PluginProbingContext context, System.Type type);
protected virtual bool IsPluginFastPreCheck(Orc.Extensibility.PluginProbingContext context, System.Type type) { }
Expand Down
32 changes: 32 additions & 0 deletions src/Orc.Extensibility/Services/PluginFinderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ protected virtual async Task FindPluginsInAssemblyAsync(PluginProbingContext con
return;
}

// Register assembly in their own plugin load context
await _runtimeAssemblyResolverService.RegisterAssemblyAsync(assemblyPath);

// Important: all types already in the app domain should be included as well
Expand Down Expand Up @@ -430,6 +431,8 @@ protected virtual async Task FindPluginsInAssemblyAsync(PluginProbingContext con

protected virtual List<string> FindResolvableAssemblyPaths(string assemblyPath)
{
var assemblyVersions = new Dictionary<string, Version>(StringComparer.OrdinalIgnoreCase);

if (_appDomainResolvablePaths.Count == 0)
{
foreach (var loadedAssembly in AppDomain.CurrentDomain.GetLoadedAssemblies())
Expand All @@ -452,6 +455,11 @@ protected virtual List<string> FindResolvableAssemblyPaths(string assemblyPath)
}

_appDomainResolvablePaths.Add(location);

var fileName = Path.GetFileNameWithoutExtension(location);
var version = GetFileVersion(location);

assemblyVersions[fileName] = version;
}
}

Expand All @@ -465,13 +473,37 @@ where x.PluginLocation.EqualsIgnoreCase(assemblyPath)
{
foreach (var runtimeAssembly in pluginLoadContext.RuntimeAssemblies)
{
if (!_fileService.Exists(runtimeAssembly.Location))
{
continue;
}

var fileName = Path.GetFileNameWithoutExtension(runtimeAssembly.Location);
var version = GetFileVersion(runtimeAssembly.Location);

if (assemblyVersions.TryGetValue(fileName, out var existingVersion))
{
if (existingVersion != version)
{
Log.Warning($"Already loaded '{fileName}' version '{existingVersion}', but also found runtime assembly '{version}'. The already loaded assembly will be used to investigate '{assemblyPath}'");
continue;
}
}

assemblyVersions[fileName] = version;

paths.Add(runtimeAssembly.Location);
}
}

return paths;
}

protected virtual Version GetFileVersion(string fileName)
{
return AssemblyName.GetAssemblyName(fileName)?.Version ?? new Version("0.0.0");
}

protected virtual bool ShouldIgnoreAssembly(string assemblyPath)
{
var fileName = Path.GetFileName(assemblyPath).ToLower();
Expand Down

0 comments on commit 78a4b4b

Please sign in to comment.