Skip to content

Commit

Permalink
Add better GetAssemblyByName debug (#4192)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Jul 29, 2023
1 parent 9969899 commit 7c3634f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Robust.Shared/ContentPack/AppDomainExt.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using Robust.Shared.Collections;

namespace Robust.Shared.ContentPack
{
Expand All @@ -14,7 +15,23 @@ public static class AppDomainExt
/// <returns></returns>
public static Assembly GetAssemblyByName(this AppDomain domain, string name)
{
return domain.GetAssemblies().Single(assembly => assembly.GetName().Name == name);
var assemblies = new ValueList<Assembly>(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];
}
}
}

0 comments on commit 7c3634f

Please sign in to comment.