From 8d516ee4c70cbd62805cb601576d06614030c57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Wed, 12 Apr 2023 00:24:20 +0800 Subject: [PATCH] fix: add a try catch for loading one assembly. --- RotationSolver/Updaters/RotationUpdater.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 24d9a655c..d36210b3b 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -87,6 +87,21 @@ public static async void GetAllCustomRotations() if (hasDownload) LoadRotationsFromLocal(relayFolder); } + private static Assembly LoadOne(string filePath) + { + try + { + var assembly = RotationHelper.LoadFrom(filePath); + PluginLog.Log("Successfully loaded " + assembly.FullName); + return assembly; + } + catch (Exception ex) + { + PluginLog.Log("Failed to load " + filePath, ex); + } + return null; + } + private static void LoadRotationsFromLocal(string relayFolder) { var directories = Service.Config.OtherLibs @@ -97,9 +112,9 @@ private static void LoadRotationsFromLocal(string relayFolder) var assemblies = from dir in directories where Directory.Exists(dir) from l in Directory.GetFiles(dir, "*.dll") - select RotationHelper.LoadFrom(l); - - PluginLog.Log("Try to load rotations from these assemblies.\n" + string.Join('\n', assemblies.Select(a => "- " + a.FullName))); + select LoadOne(l) into a + where a != null + select a; AuthorHashes = new SortedList( (from a in assemblies