mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Allow multiple versions of an assembly to be loaded into AppDomain
This commit is contained in:
1 parent
8d0802b4fc
commit
9cce4e4222
1 file changed
+11
-2
@@ -40,8 +40,17 @@ namespace BepInEx.Preloader
|
||||
|
||||
// Use parse assembly name on managed side because native GetName() can fail on some locales
|
||||
// if the game path has "exotic" characters
|
||||
var foundAssembly = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.FirstOrDefault(x => Utility.TryParseAssemblyName(x.FullName, out var name) && name.Name == assemblyName.Name);
|
||||
var validAssemblies = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.Select(a => new { assembly = a, name = Utility.TryParseAssemblyName(a.FullName, out var name) ? name : null })
|
||||
.Where(a => a.name != null && a.name.Name == assemblyName.Name)
|
||||
.OrderByDescending(a => a.name.Version)
|
||||
.ToList();
|
||||
|
||||
// First try to match by version, then just pick the best match (generally highest)
|
||||
// This should mainly affect cases where the game itself loads some assembly (like Mono.Cecil)
|
||||
var foundMatch = validAssemblies.FirstOrDefault(a => a.name.Version == assemblyName.Version) ?? validAssemblies.FirstOrDefault();
|
||||
var foundAssembly = foundMatch?.assembly;
|
||||
|
||||
if (foundAssembly != null)
|
||||
return foundAssembly;
|
||||
|
||||
Reference in new issue
Block a user