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.