PostSharp 2.0 BadImageFormatException
Asked Answered
C

3

6

We have an application here which is using postsharp to wrap certain methods within a transaction aspect derived from MethodInterceptionAspect. We use NHibernate 2.0 as an ORM for the application. There is a failure within this block of code,

public override void OnInvoke(MethodInterceptionArgs args)
{
    using (TransactionScope transaction = CreateTransactionScope())
    {
        args.Proceed();
        transaction.Complete();
    }
}

that results in the following error: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) This only seems to happen for calls to save, and not delete or get calls.

I was wondering if anyone had encountered anything similar ever?

Chunky answered 21/1, 2010 at 1:3 Comment(0)
D
1

Yes, I've encountered this. Usually its a 64/32 bit problem. Check the target in your project settings.

Dariadarian answered 21/1, 2010 at 1:37 Comment(2)
Target was set to any cpu, which is x64 in my case. I'm fairly certain it's not a 64/32 bit problem since the entire stack is 64 bit.Chunky
+ 1. I virtually guarantee this is a x64/32 bit problem.Everything
S
1

Jfar is right; That exception means that you either have 64-bit code calling 32-bit code, or vice versa.

I've encountered it before as well.

Here are the steps I used to fix it:

  1. Check whether the host OS this is run on is 64-bit.
  2. Verify (for our debugging purposes) that the build is not targeting "Any-CPU". Force it to target 64 bit if all of the DLLs you're using are 64 bit (see steps #2 and #3), otherwise target 32-bit otherwise.

  3. Check your PostSharp download and make sure it's a 64-bit DLL.

  4. Check NHibernate 2.0, and make sure you're using the 64-bit version.

You cannot mix 32-bit DLLs and a 64-bit application (or vice-versa.

If none of that works, try the steps outlined here.

Sevenfold answered 24/6, 2011 at 13:25 Comment(0)
C
0

That's odd. What tells PEVERIFY if you execute it on PostSharp output?

Confined answered 22/1, 2010 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.