首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET AnyCPU项目链接平台特定库

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

Stack Overflow用户
提问于 2012-07-24 11:22:31
回答 1查看 1.6K关注 0票数 5

可能重复: 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.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 13:15:58

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

代码语言:javascript
复制
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);
}

并设置事件处理程序。

代码语言:javascript
复制
AppDomain.CurrentDomain.AssemblyResolve += SQLitePlatformSpecificResolve;

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

谢谢。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11629807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档