gpt4 book ai didi

.NET AnyCPU 项目链接平台特定库

转载 作者:行者123 更新时间:2023-12-02 15:23:51 26 4
gpt4 key购买 nike

Possible Duplicate:
Loading x86 or x64 assembly

我正在尝试编译任何 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.

最佳答案

主要问题是我在 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 平台上的 x86 程序集和 64 位平台上的 x64 程序集。

谢谢。

关于.NET AnyCPU 项目链接平台特定库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com