summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Program.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-11-30 22:44:40 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-11-30 22:44:40 -0500
commit44dfb6fac5650aa2c10cc76832d836a440ad8a2d (patch)
tree16e054ffc01526d180fc6601ad876dec7a38da5e /src/StardewModdingAPI/Program.cs
parent0fcf29d42854017b1c0b0a2aa4f6a148be6c4ddf (diff)
downloadSMAPI-44dfb6fac5650aa2c10cc76832d836a440ad8a2d.tar.gz
SMAPI-44dfb6fac5650aa2c10cc76832d836a440ad8a2d.tar.bz2
SMAPI-44dfb6fac5650aa2c10cc76832d836a440ad8a2d.zip
fix assembly resolution failing for rewritten mods that reference a different version of Json.NET (#166)
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r--src/StardewModdingAPI/Program.cs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index f0686039..4ca402e5 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -303,9 +303,30 @@ namespace StardewModdingAPI
{
Program.Monitor.Log("Loading mods...");
+ // get assembly loader
ModAssemblyLoader modAssemblyLoader = new ModAssemblyLoader(Program.CachePath, Program.TargetPlatform, Program.Monitor);
- AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => modAssemblyLoader.ResolveAssembly(e.Name); // supplement Mono's assembly resolution which doesn't handle assembly rewrites very well
+ // handle assembly resolution failure
+ AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
+ {
+ // get assembly name (without version, culture, etc)
+ string shortName = e.Name.Split(new[] { ',' }, 2).First();
+
+ // one of the assembly references injected during assembly rewriting?
+ // technically this shouldn't happen, but apparently Mono's assembly resolution doesn't handle assembly rewrites very well
+ Assembly assembly = modAssemblyLoader.ResolveAssembly(shortName);
+ if (assembly != null)
+ return assembly;
+
+ // Json.NET?
+ // mods often reference one version of Json.NET, but SMAPI might use a different version
+ if (shortName == typeof(JsonConvert).Assembly.GetName().Name)
+ return typeof(JsonConvert).Assembly;
+
+ return null;
+ };
+
+ // load mods
foreach (string directory in Directory.GetDirectories(Program.ModPath))
{
// ignore internal directory