I’ve recently helped a colleague with an issue when trying to deploy our Tridion DD4T .NET project to a Dev machine. The issue was a “System.BadImageFormatException” related to the Tridion’s Java wrapper Juggernet.
However, at first we were getting the error: “Unable to load DLL ‘xmogrt': The specified module could not be found. (Exception from HRESULT: 0x8007007E)”. It was weird because on my VM, with the exact same files in the bin, it ran fine. Turns out, it worked on my VM because my %TRIDION_HOME% was set with the file in it.
We followed the answers in this post (which you’ve probably read already before coming to this article: http://stackoverflow.com/questions/13918310/unable-to-load-dll-xmogrt-from-tridion-metadata-query) and placed the xmogrt.dll and its dependencies in the bin. However, we now ended with the “System.BadImageFormatException”:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Server Error in '/' Application. An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Here is how we solved the problem:
- Uninstall all Java (you may have several versions of the JVM installed. Uninstall all of them)
- Install the latest Java 6 JRE (though we installed the JDK 1.6_45).
- Check that it’s successfully installed by typing java –version from the command line.
- Verify that ‘xmogrt.dll’ is in the bin folder of your app and is not corrupt. In our case the ‘xmogrt.dll’ file was only 840kb for some reason. It should be 1630 KB.
- Do an iisreset.
Here is the long answer
xmogrt.dll is an unmanaged C++ assembly that is largely the Juggernet Java wrapper used by Tridion (if you’ve wondered about those jar files in the bin/lib). This compilation version of this DLL must match the CPU instructionset, i.e. x86 or x86-64). It must also match the latest Tridion-supported Java version, i.e. 1.6_xx x86 or 1.6_xx 64-bit (of java 1.7 for Tridion 2013). If there is a mismatch in either, then you’ll receive the “System.BadImageFormatException” error.Look at the Juggernet documentation for more details about how Juggernet works and this error here: http://codemesh.com/products/vfour/tutorial/dotnet/v3/L_02_run_app.html, scroll down to the section “Common Runtime Issues You Might Encounter”. Also, the Juggernet architecture diagram (found here: http://codemesh.com/products/vfour/dotnetruntimes.html) provides a nice deal of insight into understanding how the Tridion CD API is converted to .NET.