PostSharp 2.0 BadImageFormatException

We have an application that uses postharp to transfer certain methods to the transaction aspect derived from MethodInterceptionAspect. We use NHibernate 2.0 as the ORM for the application. There is a failure in this code block,

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

resulting in the following error: System.BadImageFormatException: An attempt was made to load a program with the wrong format. (Exception from HRESULT: 0x8007000B) This occurs only for calls to save, and not to delete or receive calls.

I was wondering if anyone had seen such a thing like that?

+6
asp.net-mvc postsharp
source share
3 answers

Yes, I came across this. This is usually a 64/32 bit issue. Check the target in your project settings.

+1
source share

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

I have encountered this before.

Here are the steps I used to fix it:

  • Check if the host system is 64-bit.
  • Confirm (for our debugging purposes) that the assembly is not aimed at "Any-CPU". Force it to the target 64-bit if all the DLL files you use are 64-bit (see Steps 2 and 3), otherwise 32-bit.

  • Check your PostSharp download and make sure it has a 64-bit DLL.

  • Check NHibernate 2.0 and make sure you are using the 64-bit version.

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

If nothing works, try the steps .

+1
source share

This is strange. What does PEVERIFY say if you execute it on PostSharp output?

0
source share

All Articles