Skip to content

Commit

Permalink
Closes #2458
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Nov 27, 2021
1 parent f97dc5f commit d5233c5
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions ArchiSteamFarm/Core/ASF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,23 @@ private static void LoadAllAssemblies() {
private static void LoadAssembliesNeededBeforeUpdate() {
HashSet<string> loadedAssembliesNames = GetLoadedAssembliesNames();

foreach (Assembly assembly in AssembliesNeededBeforeUpdate.Where(assemblyName => !loadedAssembliesNames.Contains(assemblyName)).Select(Assembly.Load)) {
foreach (string assemblyName in AssembliesNeededBeforeUpdate.Where(loadedAssembliesNames.Add)) {
Assembly assembly;

try {
assembly = Assembly.Load(assemblyName);
} catch (Exception e) {
ArchiLogger.LogGenericDebuggingException(e);

continue;
}

LoadAssembliesRecursively(assembly, loadedAssembliesNames);
}
}

[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
private static void LoadAssembliesRecursively(Assembly assembly, ICollection<string> loadedAssembliesNames) {
private static void LoadAssembliesRecursively(Assembly assembly, ISet<string> loadedAssembliesNames) {
if (assembly == null) {
throw new ArgumentNullException(nameof(assembly));
}
Expand All @@ -453,10 +463,18 @@ private static void LoadAssembliesRecursively(Assembly assembly, ICollection<str
throw new ArgumentNullException(nameof(loadedAssembliesNames));
}

foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies().Where(assemblyName => !loadedAssembliesNames.Contains(assemblyName.FullName))) {
loadedAssembliesNames.Add(assemblyName.FullName);
foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies().Where(assemblyName => loadedAssembliesNames.Add(assemblyName.FullName))) {
Assembly loadedAssembly;

try {
loadedAssembly = Assembly.Load(assemblyName);
} catch (Exception e) {
ArchiLogger.LogGenericDebuggingException(e);

continue;
}

LoadAssembliesRecursively(Assembly.Load(assemblyName), loadedAssembliesNames);
LoadAssembliesRecursively(loadedAssembly, loadedAssembliesNames);
}
}

Expand Down

0 comments on commit d5233c5

Please sign in to comment.