U4-8984 Upgrade AutoMapper to latest 3.x

This commit is contained in:
Claus
2016-09-16 21:21:14 +02:00
parent aea735f20e
commit 4887302b51
12 changed files with 54 additions and 27 deletions

View File

@@ -48,6 +48,9 @@ namespace Umbraco.Core
LogHelper.Error<UmbracoApplicationBase>(msg, exception);
};
// this only gets called when an assembly can't be resolved
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
//boot up the application
GetBootManager()
.Initialize()
@@ -58,6 +61,22 @@ namespace Umbraco.Core
ApplicationEventsResolver.Current.Dispose();
}
/// <summary>
/// Called when an assembly can't be resolved. In here we can do magic with the assembly name and try loading another.
/// This is used for loading a signed assembly of AutoMapper (v. 3.1+) without having to recompile old code.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
// ensure the assembly is indeed AutoMapper and that the PublicKeyToken is null before trying to Load again
// do NOT just replace this with 'return Assembly', as it will cause an infinite loop -> stackoverflow
if (args.Name.StartsWith("AutoMapper") && args.Name.EndsWith("PublicKeyToken=null"))
return Assembly.Load(args.Name.Replace(", PublicKeyToken=null", ", PublicKeyToken=be96cd2c38ef1005"));
return null;
}
/// <summary>
/// Initializes the Umbraco application
/// </summary>