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);
}