5

可能重复:
加载 x86 或 x64 程序集

我正在尝试编译 Any CPU .NET 项目,但我必须链接 SQLite 库,该库具有不同版本的 x86 和 x64 平台。仅将 DLL 版本更改为 x64 没有帮助,应用程序无法启动,我需要使用 x64 参考重新编译代码。当我同时添加 x86 和 x64 引用时,由于冲突,它无法编译。我无法使用 x86 编译应用程序,因为我使用的系统 COM 库之一在 WOW64 下不起作用。

All 32-bit VSS applications (requesters, providers, and writers) must run as native 32-bit or 64-bit applications. Running them under WOW64 is not supported

http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/eadf5dcd-fbd1-4224-9a56-b5843efebb15/

所以我需要构建任何 CPU 项目,但目前我看到的解决这个问题的唯一方法是为 x86 和 x64 提供重复的项目。有更好的吗?

更新

当我在项目中引用 x64 库,但尝试加载 x86 库时,出现以下异常。

The located assembly's manifest definition does not match the assembly reference.

4

1 回答 1

6

主要问题是我为 x86 和 x64 使用不同版本的 SQLite。我添加了方法

static private Assembly SQLitePlatformSpecificResolve(object sender, ResolveEventArgs args)
{
    string platform = Environment.Is64BitProcess ? "x64" : "x86";
    string assemblyName = new AssemblyName(args.Name).Name;
    string assemblyPath = Path.Combine(
        Environment.CurrentDirectory, "SQLite", platform, assemblyName + ".dll");

    return !File.Exists(assemblyPath) ? null : Assembly.LoadFrom(assemblyPath);
}

并设置事件处理程序

AppDomain.CurrentDomain.AssemblyResolve += SQLitePlatformSpecificResolve;

在主应用程序入口点。现在它为 x86 平台和 64 位平台上的 x64 加载 x86 程序集。

谢谢。

于 2012-07-24T13:15:58.860 回答