summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/StardewModdingAPI/Framework/ModAssemblyLoader.cs5
-rw-r--r--src/StardewModdingAPI/Program.cs23
2 files changed, 24 insertions, 4 deletions
diff --git a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
index e095cde8..6c5e6032 100644
--- a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs
@@ -103,10 +103,9 @@ namespace StardewModdingAPI.Framework
}
/// <summary>Resolve an assembly from its name.</summary>
- /// <param name="name">The assembly name.</param>
- public Assembly ResolveAssembly(string name)
+ /// <param name="shortName">The short assembly name.</param>
+ public Assembly ResolveAssembly(string shortName)
{
- string shortName = name.Split(new[] { ',' }, 2).First();
return this.AssemblyMap.Targets.FirstOrDefault(p => p.GetName().Name == shortName);
}
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