我正在为 Microsoft 项目使用 VSTO 开发加载项,并且我有一个托管 c++ dll,它包装了一个非托管 c++ dll。我需要部署两个版本的托管 c++ dll,一个用于 64 位,一个用于 32 位。我正在使用 Assembly.LoadFrom(path) 加载适当的 dll,具体取决于我运行的 Office 版本。这一切似乎在我的开发机器上运行良好,这是一台运行 64 位办公室的 64 位机器。以下是有问题的代码:
try
{
//This will return true so I know the file exists
bool fileExists = File.Exists(path);
//This will throw a file not found exception
keyModAssembly = Assembly.LoadFrom(path);
}
catch (FileNotFoundException e)
{
}
我已经三次检查了路径并且文件存在并且是正确的 32 位 dll。这一切在我的 64 位机器上运行良好,但在我尝试测试 32 位版本时在 xpmode 中失败。
任何建议将不胜感激。
提前致谢。
编辑
为了响应 Phillip 关于可能找不到非托管 dll 的建议,我正在使用 LoadLibraryW(path) 将非托管 dll 加载到作用域中。
// this is not throwing an exception so I know the unmanaged dll is there.
if (!File.Exists(unmanagedPath))
throw new FileNotFoundException();
LoadLibraryW(unmangedlibPath);