From 7c3634f1f5df8be1781a63bb7e9ab8d75db23551 Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Sun, 30 Jul 2023 03:32:02 +1000
Subject: [PATCH] Add better GetAssemblyByName debug (#4192)
---
Robust.Shared/ContentPack/AppDomainExt.cs | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/Robust.Shared/ContentPack/AppDomainExt.cs b/Robust.Shared/ContentPack/AppDomainExt.cs
index a4a9177bd62..22c6ba95108 100644
--- a/Robust.Shared/ContentPack/AppDomainExt.cs
+++ b/Robust.Shared/ContentPack/AppDomainExt.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
+using Robust.Shared.Collections;
namespace Robust.Shared.ContentPack
{
@@ -14,7 +15,23 @@ public static class AppDomainExt
///
public static Assembly GetAssemblyByName(this AppDomain domain, string name)
{
- return domain.GetAssemblies().Single(assembly => assembly.GetName().Name == name);
+ var assemblies = new ValueList(1);
+
+ foreach (var assembly in domain.GetAssemblies())
+ {
+ if (assembly.GetName().Name != name)
+ continue;
+
+ assemblies.Add(assembly);
+ }
+
+ if (assemblies.Count != 1)
+ {
+ var assemblyDesc = string.Join(" ", assemblies.Select(o => o.GetName().Name));
+ throw new InvalidOperationException($"Expected 1 assembly for {name}, found {assemblies.Count}. Found {assemblyDesc}");
+ }
+
+ return assemblies[0];
}
}
}