Troubleshoot a .BadImageFormatException system:

When debugging through a .NET 3.5 SP1 project that communicates with a local web service, I get an exception

System.BadImageFormatException: "Bad class token"

Of course, there is not much detail about what causes the exception.

I can say that the method where this happens, which is in the same class as the caller, does not reach the debugger. This exception occurs when a method is called that communicates with the web service. I have other ways to communicate with the web service, so the link is good.

My unit tests for a method also fail with the same exception.
Correction : my unit tests for the method are successful, which leads to confusion.

Does anyone know a way to track this exception? I read the documentation for the exception class, which leads me to believe that one of the assemblies is incorrect in its version or a problem with the assembly.

What other steps would you suggest when resolving this exception?

+2
source share
2 answers

Turns out I was getting this exception due to some anomalies in MSTest. I switched to xUnit.net, and since then everything has been fine.

+1
source

Running peverify.exe on an assembly can provide useful diagnostics.

http://msdn.microsoft.com/en-us/library/62bwd2yd.aspx

+3
source

All Articles