From 5e68400c43000f07a29103cacccacde72b0cce2e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 3 Feb 2017 20:12:42 -0500 Subject: only read assembly from memory if it was rewritten (#229) This fixes an issue where you can't debug into mod code because SMAPI isn't loading the actual DLL. --- src/StardewModdingAPI/Framework/AssemblyLoader.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/StardewModdingAPI/Framework') diff --git a/src/StardewModdingAPI/Framework/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/AssemblyLoader.cs index 8b2f29e1..123211b9 100644 --- a/src/StardewModdingAPI/Framework/AssemblyLoader.cs +++ b/src/StardewModdingAPI/Framework/AssemblyLoader.cs @@ -72,14 +72,19 @@ namespace StardewModdingAPI.Framework Assembly lastAssembly = null; foreach (AssemblyParseResult assembly in assemblies) { - this.Monitor.Log($"Loading {assembly.File.FullName}...", LogLevel.Trace); - this.RewriteAssembly(assembly.Definition); - using (MemoryStream outStream = new MemoryStream()) + this.Monitor.Log($"Loading {assembly.File.Name}...", LogLevel.Trace); + bool changed = this.RewriteAssembly(assembly.Definition); + if (changed) { - assembly.Definition.Write(outStream); - byte[] bytes = outStream.ToArray(); - lastAssembly = Assembly.Load(bytes); + using (MemoryStream outStream = new MemoryStream()) + { + assembly.Definition.Write(outStream); + byte[] bytes = outStream.ToArray(); + lastAssembly = Assembly.Load(bytes); + } } + else + lastAssembly = Assembly.UnsafeLoadFrom(assembly.File.FullName); } // last assembly loaded is the root -- cgit