PostSharp 在应用于通用方法时会导致 BadImageException - 运行 peverify.exe 时出错
我刚刚将一个项目从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(对象和实例,参数参数,对象方面参数) 在 PostSharp.Aspects.Internals.MethodInterceptionArgsImpl.Proceed() 在 C:\COMPANY\Code\COMPANY-NET4.0\Core\Aop\TransactionAspectAttribute.cs 中的 COMPANY.Aop.TransactionAspectAttribute.OnInvoke(MethodInterceptionArgs context):第 68 行 在 C:\COMPANY\Code\COMPANY-NET4.0\Core\DataAccess\NHibernate\BaseRepository.cs 中的 COMPANY.Data.NHibernate.BaseRepository.Save[T](T ScoreBigModel):第 102 行 在 C:\COMPANY\Code\COMPANY-NET4.0\UnitTests\DataAccess\NHibernate\CanonicalTermRepositorySpecs.cs 中的 COMPANY.UnitTests.DataAccess.NHibernate.when_ saving_a_canonical_term.<.ctor>b__5() 处:第 29 行 在 Machine.Specifications.Utility.RandomExtensionMethods.InvokeIfNotNull(因为因为) 在 Machine.Specifications.Model.Context.EstablishContext()
当我在程序集上运行 peverify.exe 时,我看到以下形式的数百个错误。通用方法似乎总是存在问题:
[IL]: Error: [C:\COMPANY\Code\COMPANY-NET4.0\Core\bin\Debug\COMPANY.Core.dll : COMPANY.Data.NHibernate.ActivationRepository+c__Binding ::Invoke][偏移 0x0000008D][找到引用 'PostSharp.Aspects.Internals.MethodBinding'][预期引用 '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] [在堆栈上发现引用 'PostSharp.Aspects.Internals.MethodBinding`1[COMPANY.Models.Activation]'][预期引用 'PostSharp.Aspects.Internals.MethodBinding'] 意外类型。
我正在运行最新版本的 PostSharp 2.0 RC。
I just upgraded a project from VS2008/.NET 3.5/PostSharp 1.5 to VS2010/.NET4.0/PostSharp 2.0.
Now, when running the unit tests for the system I get hundereds exceptions in the form of:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at COMPANY.Data.NHibernate.BaseRepository.c__Binding`1.Invoke(Object& instance, Arguments arguments, Object aspectArgs)
at PostSharp.Aspects.Internals.MethodInterceptionArgsImpl.Proceed()
at COMPANY.Aop.TransactionAspectAttribute.OnInvoke(MethodInterceptionArgs context) in C:\COMPANY\Code\COMPANY-NET4.0\Core\Aop\TransactionAspectAttribute.cs:line 68
at COMPANY.Data.NHibernate.BaseRepository.Save[T](T scoreBigModel) in C:\COMPANY\Code\COMPANY-NET4.0\Core\DataAccess\NHibernate\BaseRepository.cs:line 102
at COMPANY.UnitTests.DataAccess.NHibernate.when_saving_a_canonical_term.<.ctor>b__5() in C:\COMPANY\Code\COMPANY-NET4.0\UnitTests\DataAccess\NHibernate\CanonicalTermRepositorySpecs.cs:line 29
at Machine.Specifications.Utility.RandomExtensionMethods.InvokeIfNotNull(Because because)
at Machine.Specifications.Model.Context.EstablishContext()
When I run peverify.exe on the assembly, I see hundreds of errors in the following form. Always seems to be issues with generic methods:
[IL]: Error: [C:\COMPANY\Code\COMPANY-NET4.0\Core\bin\Debug\COMPANY.Core.dll : COMPANY.Data.NHibernate.ActivationRepository+c__Binding::Invoke][offset 0x0000008D][found ref 'PostSharp.Aspects.Internals.MethodBinding'][expected ref 'PostSharp.Aspects.Internals.MethodBinding`1[COMPANY.Models.Activation]'] Unexpected type on the stack.
[IL]: Error: [C:\COMPANY\Code\COMPANY-NET4.0\Core\bin\Debug\COMPANY.Core.dll : COMPANY.Data.NHibernate.ActivationRepository+c__Binding::Invoke][offset 0x00000056][found ref 'PostSharp.Aspects.Internals.MethodBinding`1[COMPANY.Models.Activation]'][expected ref 'PostSharp.Aspects.Internals.MethodBinding'] Unexpected type on the stack.
I am running the latest release of PostSharp 2.0 RC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“System.BadImageFormatException”通常表示 64 位/32 位问题。
如果您为“任何 CPU”编译代码并在 64 位处理器上运行它,它将被 JIT 编译为 64 位。如果它随后调用任何 32 位代码(例如,在非托管 dll 中),当它尝试从 64 位代码跳转到 32 位代码时,您将收到此异常。
如果您在 64 位操作系统上运行,则升级中的某些内容可能会导致您的程序中混合有 32 位和 64 位代码。不过,如果您在 32 位操作系统上运行,那么就不会出现问题,在这种情况下,它可能表明二进制文件已损坏。
如果是32/64,则可以执行以下操作:
- 确保您使用的所有 dll 与您的应用程序具有相同的位数,或者
- 如果您无法用 64 位版本替换某些 32 位 dll,请尝试将您的应用程序编译为“x86”而不是“任何 CPU”。这将迫使它即使在 64 位 PC 上也被编译为 32 位代码,这意味着它必须作为 32 位应用程序在 WoW64 下运行,但它将与其 32 位 dll 兼容。
"System.BadImageFormatException" usually indicates a 64-bit/32-bit problem.
If you compile your code for "Any CPU" and run it on a 64-bit processor it will be JIT compiled to 64 bit. If it then calls any code (e.g. in an unmanaged dll) that is 32-bit, you'll get this exception when it tries to jump from 64-bit to 32-bit code.
If you're running on a 64-bit OS it's therefore possible that something in your upgrade has caused your program to get a mixture of 32-bit and 64-bit code in it. If you're running on a 32-bit OS then then can't be the problem, though, in which case it may indicate a corrupted binary.
If it is 32/64, then you can do the following:
- Make sure all the dlls you use are the same bit-ness as your app, or
- If you can't replace some 32-bit dlls with 64-bit versions, try compilng your app as "x86" rather than "Any CPU". This will force it to be compiled to 32-bit code even on a 64-bit PC, which will mean it has to run under WoW64 as a 32-bit app but it will be compatible with its 32-bit dlls.
该问题正在此处解决:http://www.sharpcrafters.com/forum /Topic4896-19-1.aspx
The issue is being adressed here: http://www.sharpcrafters.com/forum/Topic4896-19-1.aspx