解决依赖库多版本重定向问题
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var splitters = args.Name?.Split(','); if (splitters == null || splitters.Length < 4) return null; var publicToken = splitters[3].Replace(" ",""); if ("PublicKeyToken=null".Equals(publicToken,StringComparison.OrdinalIgnoreCase)) { return null; } var firstItem = splitters[0] + ".dll"; var matchDll = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, firstItem); if (File.Exists(matchDll)) { Log.Info($"{args.Name}反射失败,尝试重定向"); return Assembly.LoadFrom(matchDll); } return null; }
参考:
https://www.cnblogs.com/yangzhj/p/16773593.html