Question

In my server I'm getting an exception which I catch and it seems to be ok.

The problem is that when I'm writing its StackTrace I'm getting BadImageFormatException.

I've tried to debug the server. Stopped on a breakpoint when catching the exception, I can see all its fields, but in the StackTrace I see the BadImageFormatException.

Any ideas what causes to this problem?

My server details -

It is written in C# with .NET FW 4.
I also use FrameWork which is written in Managed C++.
I compile my server to x86 platform. And run the server on x64 machine.

The full BadImageFormatException -

System.BadImageFormatException: The parameters and the signature of the method don't match. at System.Reflection.RuntimeParameterInfo.GetParameters(IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, ParameterInfo& returnParameter, Boolean fetchReturnParameter) at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters() at System.Reflection.RuntimeMethodInfo.GetParameters() at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat) at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo) at System.Exception.GetStackTrace(Boolean needFileInfo) at System.Exception.ToString(Boolean needFileLineInfo) at System.Exception.ToString() at log4net.ObjectRenderer.DefaultRenderer.RenderObject(RendererMap rendererMap, Object obj, TextWriter writer) at log4net.ObjectRenderer.RendererMap.FindAndRender(Object obj, TextWriter writer)

Was it helpful?

Solution

Do you use Spring.NET? Recently I had the same problem when implementing IErrorHandler in WCF to log exceptions and in my case problem was in Spring.NET. I've updated Spting.NET to version 1.3.1 and now it works fine.

from changelog [SPRNET-1284] - IL code generation can result in System.BadImageFormatException in Windows 2008

OTHER TIPS

This happens if your executing process is running as x86 (if set to anycpu and running on a win32bit machine) but somewhere down the road it tries to load an assembly that has explicitely compiled as x64.. or vice versa. x64(or anycpu on x64 machine) tries to load an explicit x86 compiled assembly.

Some obfuscators can cause this exception when they inject invalid metadata.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top