From 9bfdc15418c27e25198492f6cb848fc2b30adf4a Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 22 Feb 2022 18:51:04 -0800 Subject: [PATCH] InitializeAssemblies: catch exceptions --- QSB/QSBCore.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index d948bcf7..4d46d149 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -1,4 +1,5 @@ -using Mirror; +using HarmonyLib; +using Mirror; using OWML.Common; using OWML.ModHelper; using QSB.Menus; @@ -123,12 +124,25 @@ namespace QSB DebugLog.DebugWrite("Running RuntimeInitializeOnLoad methods for our assemblies", MessageType.Info); foreach (var path in Directory.EnumerateFiles(Helper.Manifest.ModFolderPath, "*.dll")) { - var assembly = Assembly.LoadFile(path); - DebugLog.DebugWrite(assembly.ToString()); - assembly.GetTypes() - .SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)) - .Where(x => x.IsDefined(typeof(RuntimeInitializeOnLoadMethodAttribute))) - .ForEach(x => x.Invoke(null, null)); + try + { + var assembly = Assembly.LoadFile(path); + DebugLog.DebugWrite(assembly.ToString()); + assembly + .GetTypes() + .SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)) + .Where(x => x.IsDefined(typeof(RuntimeInitializeOnLoadMethodAttribute))) + .ForEach(x => x.Invoke(null, null)); + } + catch (ReflectionTypeLoadException e) + { + DebugLog.DebugWrite(e.ToString(), MessageType.Error); + DebugLog.DebugWrite(e.LoaderExceptions.Join(x => "\t" + x, "\n"), MessageType.Error); + } + catch (Exception e) + { + DebugLog.DebugWrite(e.ToString(), MessageType.Error); + } } DebugLog.DebugWrite($"Assemblies initialized", MessageType.Success);