。net AnyCPU项目链接平台特定库[副本]

时间:2023-01-17 10:41:35

Possible Duplicate:
Loading x86 or x64 assembly

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

I'm trying to compile Any CPU .NET project, but I have to link SQLite library which has different versions for x86 and x64 platforms. Changing only DLL versions to x64 doesn't help, application doesn't start, I need to recompile code using x64 reference. When I add both x86 and x64 references it fails to compile, because of conflicts. I can't compile application using x86, because one of the system COM libraries I'm using doesn't work under WOW64.

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

所有32位的VSS应用程序(请求者、提供者和作者)必须作为本地32位或64位应用程序运行。不支持在WOW64下运行它们

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

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

so I need to build Any CPU project, but the only solution to this problem I see at the moment is having duplicate projects for x86 and x64. Is there anything better?

因此,我需要构建任何CPU项目,但是目前我看到的这个问题的唯一解决方案是对x86和x64进行重复项目。有什么更好?

UPDATE

更新

When I reference x64 libraries in project, but try to load x86 libraries I get the following exception.

当我在项目中引用x64库时,但是尝试加载x86库,我得到了下面的异常。

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

定位程序集的清单定义与程序集引用不匹配。

1 个解决方案

#1


6  

The main problem was the fact that I was using different versions of SQLite for x86 and x64. I added method

主要的问题是我在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);
}

And set event handler

并设置事件处理程序

AppDomain.CurrentDomain.AssemblyResolve += SQLitePlatformSpecificResolve;

in main application entry point. Now it loads x86 assembly for x86 platforms and x64 on 64 bit platforms correspondingly.

在主应用程序入口点。现在,它在64位平台上加载x86平台和64位平台的x86汇编。

Thanks.

谢谢。

#1


6  

The main problem was the fact that I was using different versions of SQLite for x86 and x64. I added method

主要的问题是我在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);
}

And set event handler

并设置事件处理程序

AppDomain.CurrentDomain.AssemblyResolve += SQLitePlatformSpecificResolve;

in main application entry point. Now it loads x86 assembly for x86 platforms and x64 on 64 bit platforms correspondingly.

在主应用程序入口点。现在,它在64位平台上加载x86平台和64位平台的x86汇编。

Thanks.

谢谢。