SideBySide Error with Binding Redirect in .net Windows Service

末鹿安然 提交于 2019-12-02 00:36:05
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;
        }; 
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!