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.cs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
index eb940c41..01037870 100644
--- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
+++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
@@ -264,8 +264,15 @@ 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 (this.AssemblyDefinitionResolver.TryAddSearchDirectory(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 +293,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))