如何将程序集绑定重定向到当前版本或更高版本? [英] How do I redirect assembly binding to the current version or higher?

查看:74
本文介绍了如何将程序集绑定重定向到当前版本或更高版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我的引用将Specific Version设置为false,由于目标计算机的版本更高,我仍收到程序集绑定错误.当某些目标计算机可能具有1.61.0.0版本而另一些目标计算机具有1.62.0.0或更高版本时,如何指定当前版本或更高版本以避免出现以下错误?

Even though my references have Specific Version set to false, I'm getting assembly binding errors because the target machine has a higher version. How do I specify the current version or higher to avoid the following error when some target machines might have version 1.61.0.0 while others have 1.62.0.0 or higher?

System.IO.FileLoadException: Could not load file or assembly 'ServerInterface.NET, Version=1.61.0.0, Culture=neutral, PublicKeyToken=151ae431f239ddf0' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'ServerInterface.NET, Version=1.61.0.0, Culture=neutral, PublicKeyToken=151ae431f239ddf0'

推荐答案

Redirecting the binding in code allows me to use any version. You would probably want to do more checking than this, as this redirects any failed attempts to any assembly with the same name.

public static void Main()
{
    AppDomain.CurrentDomain.AssemblyResolve += _HandleAssemblyResolve;
}

private Assembly _HandleAssemblyResolve(object sender, ResolveEventArgs args)
{
    var firstOrDefault = args.Name.Split(',').FirstOrDefault();
    return Assembly.Load(firstOrDefault);
}

这篇关于如何将程序集绑定重定向到当前版本或更高版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆