SideBySide Error with Binding Redirect in .net Windows Service

Kevin Kuszyk

Following the update from Microsoft support and a suggestion from @cmckeegan, we moved away from an external config file for our binding redirect and moved it into code instead. We now call BindingRedirects.Register() in our composition root.

The BindingRedirects class looks like this:

public static class BindingRedirects
{
    static readonly Dictionary<string, string> Redirects = new Dictionary<string, string>
    {
        { "AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005", @"AutoMapper.3.2.1\AutoMapper.dll"}    
    }; 

    public static void Register()
    {
        AppDomain.CurrentDomain.AssemblyResolve += (o, args) =>
        {
            if (Redirects.ContainsKey(args.Name))
            {
                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Redirects[args.Name]);
                return Assembly.LoadFrom(path);
            }

            return null;
        }; 
    }
}