我有一个应用程序,其中包含许多插件(MEF),这些插件连接到许多不同的I/O设备。大多数这些插件都有许多托管和非托管dll。
最近,一家制造商发布了新的固件和新的驱动程序。API保持不变。
我认为我可以在单独的资源文件夹中包含两个dll版本,并在应用程序启动时将所需的集合复制到输出文件夹中。
(我想我可以只是制作插件的第二个副本并找出加载正确插件的方法,但我认为复制DLL可能更容易 - 特别是考虑到插件代码没有改变)
但这行不通。
错误提示表明原始的DLL已被加载或应该已被加载,但未能加载。
有没有什么方法可以实现我的目标,或者我必须构建两个单独的应用程序版本?
编辑:我还应该说一下,没有必要同时加载这两个 DLL。只需使用一个参数启动应用程序,就可以加载其中一个 DLL。
最近,一家制造商发布了新的固件和新的驱动程序。API保持不变。
我认为我可以在单独的资源文件夹中包含两个dll版本,并在应用程序启动时将所需的集合复制到输出文件夹中。
(我想我可以只是制作插件的第二个副本并找出加载正确插件的方法,但我认为复制DLL可能更容易 - 特别是考虑到插件代码没有改变)
但这行不通。
static MyClass() // static constructor
{
// required version?
if (envvar.Equals("4") )
{
path = "ver4.1.1";
}
else
{
path = "ver2.5.1";
}
// location of drivers
path = Path.Combine("./Prj/QX", path);
string[] files = Directory.GetFiles(path);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
string fileName = Path.GetFileName(s);
string destFile = Path.Combine(".", fileName);
File.Copy(s, destFile, true);
}
// force load of assemby
Assembly assy = LoadWithoutCache("driver.dll");
string fn = assy.FullName;
}
static Assembly LoadWithoutCache(string path)
{
using (var fs = new FileStream(path, FileMode.Open))
{
var rawAssembly = new byte[fs.Length];
fs.Read(rawAssembly, 0, rawAssembly.Length);
return Assembly.Load(rawAssembly);
}
}
错误提示表明原始的DLL已被加载或应该已被加载,但未能加载。
Could not load file or assembly 'driver, Version=1.5.77, Culture=neutral, PublicKeyToken=983247934' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
有没有什么方法可以实现我的目标,或者我必须构建两个单独的应用程序版本?
编辑:我还应该说一下,没有必要同时加载这两个 DLL。只需使用一个参数启动应用程序,就可以加载其中一个 DLL。