summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTehPers <tehperz@gmail.com>2022-06-28 16:37:58 -0700
committerTehPers <tehperz@gmail.com>2022-06-28 16:37:58 -0700
commit0c0f7898f4ff3b2e4afdbdc438674b30be7dacc7 (patch)
tree921c5c84aec6a46e714da127e3ccc01849ccc192
parent5e1212e99aa7cb8c0333a57fa60236df79b0ac6d (diff)
downloadSMAPI-0c0f7898f4ff3b2e4afdbdc438674b30be7dacc7.tar.gz
SMAPI-0c0f7898f4ff3b2e4afdbdc438674b30be7dacc7.tar.bz2
SMAPI-0c0f7898f4ff3b2e4afdbdc438674b30be7dacc7.zip
Search assembly directory for dependencies
-rw-r--r--src/SMAPI/Framework/ModLoading/AssemblyLoader.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
index eb940c41..bd29a159 100644
--- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
+++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
@@ -264,8 +264,18 @@ namespace StardewModdingAPI.Framework.ModLoading
if (!file.Exists)
yield break; // not a local assembly
+ // add the assembly's directory temporarily if needed
+ // this is needed by F# mods which bundle FSharp.Core.dll, for example
+ string? temporarySearchDir = null;
+ if (file.DirectoryName is not null && !this.AssemblyDefinitionResolver.GetSearchDirectories().Contains(file.DirectoryName))
+ {
+ this.AssemblyDefinitionResolver.AddSearchDirectory(file.DirectoryName);
+ temporarySearchDir = file.DirectoryName;
+ }
+
// read assembly
AssemblyDefinition assembly;
+ try
{
byte[] assemblyBytes = File.ReadAllBytes(file.FullName);
Stream readStream = this.TrackForDisposal(new MemoryStream(assemblyBytes));
@@ -286,6 +296,12 @@ namespace StardewModdingAPI.Framework.ModLoading
assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true }));
}
}
+ finally
+ {
+ // clean up temporary search directory
+ if (temporarySearchDir is not null)
+ this.AssemblyDefinitionResolver.RemoveSearchDirectory(temporarySearchDir);
+ }
// skip if already visited
if (visitedAssemblyNames.Contains(assembly.Name.Name))