0

我刚刚将一个项目从 VS2008/.NET 3.5/PostSharp 1.5 升级到 VS2010/.NET4.0/PostSharp 2.0。

现在,在为系统运行单元测试时,我会遇到以下形式的数百个异常:

System.BadImageFormatException:试图加载格式不正确的程序。(HRESULT 的异常:0x8007000B)在 COMPANY.Data.NHibernate.BaseRepository.c__Binding`1.Invoke(Object& instance, Arguments arguments, Object aspectArgs) 在 COMPANY.Aop.TransactionAspectAttribute 的 PostSharp.Aspects.Internals.MethodInterceptionArgsImpl.Proceed()。 OnInvoke(MethodInterceptionArgs context) 在 C:\COMPANY\Code\COMPANY-NET4.0\Core\Aop\TransactionAspectAttribute.cs:第 68 行 COMPANY.Data.NHibernate.BaseRepository.Save[T](T scoreBigModel) 在 C:\ COMPANY\Code\COMPANY-NET4.0\Core\DataAccess\NHibernate\BaseRepository.cs:COMPANY.UnitTests.DataAccess.NHibernate.when_saving_a_canonical_term 的第 102 行。<.ctor>b__5() 在 C:\COMPANY\Code\COMPANY- NET4.0\UnitTests\DataAccess\NHibernate\CanonicalTermRepositorySpecs.cs:

当我在程序集上运行 peverify.exe 时,我看到以下形式的数百个错误。泛型方法似乎总是存在问题:

[IL]:错误:[C:\COMPANY\Code\COMPANY-NET4.0\Core\bin\Debug\COMPANY.Core.dll:COMPANY.Data.NHibernate.ActivationRepository+c__Binding::Invoke][偏移量 0x0000008D][发现 ref 'PostSharp.Aspects.Internals.MethodBinding'][expected ref 'PostSharp.Aspects.Internals.MethodBinding`1[COMPANY.Models.Activation]'] 堆栈上的意外类型。

[IL]:错误:[C:\COMPANY\Code\COMPANY-NET4.0\Core\bin\Debug\COMPANY.Core.dll:COMPANY.Data.NHibernate.ActivationRepository+c__Binding::Invoke][偏移量 0x00000056][发现 ref 'PostSharp.Aspects.Internals.MethodBinding`1[COMPANY.Models.Activation]'][expected ref 'PostSharp.Aspects.Internals.MethodBinding'] 堆栈上的意外类型。

我正在运行最新版本的 PostSharp 2.0 RC。

4

2 回答 2

1

这个问题在这里得到解决:http: //www.sharpcrafters.com/forum/Topic4896-19-1.aspx

于 2010-07-02T18:03:50.997 回答
0

“System.BadImageFormatException”通常表示 64 位/32 位问题。

如果您为“任何 CPU”编译代码并在 64 位处理器上运行它,它将被 JIT 编译为 64 位。如果它随后调用任何 32 位代码(例如,在非托管 dll 中),当它试图从 64 位跳转到 32 位代码时,您将收到此异常。

如果您在 64 位操作系统上运行,那么升级中的某些内容可能导致您的程序在其中混合了 32 位和 64 位代码。但是,如果您在 32 位操作系统上运行,那么就不是问题所在,在这种情况下,它可能表示二进制文件已损坏。

如果是 32/64,那么您可以执行以下操作: - 确保您使用的所有 dll 与您的应用程序的位数相同,或者 - 如果您无法将某些 32 位 dll 替换为 64 位版本,尝试将您的应用程序编译为“x86”而不是“任何 CPU”。这将迫使它即使在 64 位 PC 上也被编译为 32 位代码,这意味着它必须作为 32 位应用程序在 WoW64 下运行,但它将与其 32 位 dll 兼容。

于 2010-07-02T17:38:42.823 回答