Skip to content

Commit

Permalink
Fix loading plugin assemblies from deps.json on linux (case sensitive)
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Jan 26, 2025
1 parent d195a79 commit 9af9d46
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Reqnroll/Plugins/DotNetFrameworkPluginAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ Assembly TryAssemblyResolve(object sender, ResolveEventArgs args)
library.Hash,
library.RuntimeAssemblyGroups.SelectMany(g => g.AssetPaths),
library.Dependencies,
library.Serviceable);
library.Serviceable,
library.Path,
library.HashPath);

var assemblies = new List<string>();
if (assemblyResolver.TryResolveAssemblyPaths(wrapper, assemblies))
Expand Down
67 changes: 50 additions & 17 deletions Reqnroll/Plugins/PluginAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@ public PluginAssemblyResolver(string path)
{
_loadContext = AssemblyLoadContext.GetLoadContext(typeof(PluginAssemblyResolver).Assembly);
Assembly = _loadContext.LoadFromAssemblyPath(path);
_dependencyContext = DependencyContext.Load(Assembly);

_assemblyResolver = new CompositeCompilationAssemblyResolver(
[
new AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(path)!),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver()
]);
try
{
_dependencyContext = DependencyContext.Load(Assembly);

if (_dependencyContext is null)
return;

_loadContext.Resolving += OnResolving;
_loadContext.Unloading += OnUnloading;
_assemblyResolver = new CompositeCompilationAssemblyResolver(
[
new AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(path)!),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver()
]);

_loadContext.Resolving += OnResolving;
_loadContext.Unloading += OnUnloading;
}
catch (Exception)
{
// Don't throw if we can't load the dependencies from .deps.json
}
}

private void OnUnloading(AssemblyLoadContext context)
Expand All @@ -45,30 +56,52 @@ private void OnUnloading(AssemblyLoadContext context)

private Assembly OnResolving(AssemblyLoadContext context, AssemblyName name)
{
var library = _dependencyContext?.RuntimeLibraries.FirstOrDefault(
try
{
var library = _dependencyContext?.RuntimeLibraries.FirstOrDefault(
runtimeLibrary => string.Equals(runtimeLibrary.Name, name.Name, StringComparison.OrdinalIgnoreCase));

if (library != null)
{
if (library == null)
return null;

var wrapper = new CompilationLibrary(
library.Type,
library.Name,
library.Version,
library.Hash,
library.RuntimeAssemblyGroups.SelectMany(g => g.AssetPaths),
library.Dependencies,
library.Serviceable);
library.Serviceable,
library.Path,
library.HashPath);

var assemblies = new List<string>();
_assemblyResolver.TryResolveAssemblyPaths(wrapper, assemblies);

if (assemblies.Count > 0)
if (_assemblyResolver.TryResolveAssemblyPaths(wrapper, assemblies))
{
return _loadContext.LoadFromAssemblyPath(assemblies[0]);
foreach (var asm in assemblies)
{
try
{
var assembly = _loadContext.LoadFromAssemblyPath(asm);
return assembly;
}
catch
{
// Don't throw if we can't load the specified assembly (perhaps something is missing or misconfigured)
continue;
}
}
}
}

return null;
return null;
}
catch
{
// Don't throw if we can't load the dependencies from .deps.json
return null;
}
}

public static Assembly Load(string path)
Expand Down

0 comments on commit 9af9d46

Please sign in to comment.