From 43eea13a1ac3d548920ecb38b20b6b181c91d504 Mon Sep 17 00:00:00 2001 From: Lisias T Date: Sun, 7 May 2023 16:30:24 -0300 Subject: [PATCH] Throwing Exceptions when trying to load an Already Loaded Assembly. Should mitigate the https://github.com/TweakScale/Companion_Frameworks/issues/6 problem, as well any other idiot that do the same stupidity as I did. #facePalm --- Source/KSPe/Util/SystemTools.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/KSPe/Util/SystemTools.cs b/Source/KSPe/Util/SystemTools.cs index 6348fce9..9a7825b6 100644 --- a/Source/KSPe/Util/SystemTools.cs +++ b/Source/KSPe/Util/SystemTools.cs @@ -266,6 +266,12 @@ public class Exception : Assembly.Exception protected Exception(string message, string assemblyName) : base(message, assemblyName) { } } + public class AlreadyLoadedException : Exception + { + private static readonly string MESSAGE = "The Assembly {0} is already loaded!"; + internal AlreadyLoadedException(string assemblyName) : base(MESSAGE, assemblyName) { } + } + protected static readonly object MUTEX = new object(); protected readonly string effectivePath; protected readonly string searchPath; @@ -321,6 +327,8 @@ void IDisposable.Dispose() public SReflection.Assembly LoadAndStartup(string assemblyName) { + if (Assembly.Exists.ByName(assemblyName)) + throw new AlreadyLoadedException(assemblyName); return Assembly.LoadAndStartup(assemblyName); } }