summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/AssemblyLoader.cs')
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyLoader.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
index ba4c3f5c..8f5a8316 100644
--- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
+++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
@@ -99,6 +99,19 @@ namespace StardewModdingAPI.Framework.ModLoading
// rewrite assembly
bool changed = this.RewriteAssembly(mod, assembly.Definition, assumeCompatible, loggedMessages, logPrefix: " ");
+ // detect broken assembly reference
+ foreach (AssemblyNameReference reference in assembly.Definition.MainModule.AssemblyReferences)
+ {
+ if (!this.IsAssemblyLoaded(reference))
+ {
+ this.Monitor.LogOnce(loggedMessages, $" Broken code in {assembly.File.Name}: reference to missing assembly '{reference.FullName}'.");
+ if (!assumeCompatible)
+ throw new IncompatibleInstructionException($"assembly reference to {reference.FullName}", $"Found a reference to missing assembly '{reference.FullName}' while loading assembly {assembly.File.Name}.");
+ mod.SetWarning(ModWarning.BrokenCodeLoaded);
+ break;
+ }
+ }
+
// load assembly
if (changed)
{
@@ -126,6 +139,20 @@ namespace StardewModdingAPI.Framework.ModLoading
return lastAssembly;
}
+ /// <summary>Get whether an assembly is loaded.</summary>
+ /// <param name="reference">The assembly name reference.</param>
+ public bool IsAssemblyLoaded(AssemblyNameReference reference)
+ {
+ try
+ {
+ return this.AssemblyDefinitionResolver.Resolve(reference) != null;
+ }
+ catch (AssemblyResolutionException)
+ {
+ return false;
+ }
+ }
+
/// <summary>Resolve an assembly by its name.</summary>
/// <param name="name">The assembly name.</param>
/// <remarks>