The Code Jedi

Using the CodeRush Test Runner with Platform Specific Libraries

An issue appeared today for a co-worker, who was getting failing unit tests on one of our components, when the tests were being run from the CodeRush Test Runner. By the way, have I mentioned my love for CodeRush + Refactor? No? Well I do, to the point where I have a work license as well as a personal, paid for out of my own pocket, license! Unfortunately, he was getting an error whenever he ran the tests against the library, which we know has been working without issue for years. Not only that, but when he checked the build history on our build box, there was no report of failing tests. That reminds me, you ARE running your unit test suite in your Continuous Integration environment, right? Right?


He then mentioned the error he was getting, which is a BadImageFormatException getting thrown. That immediately connected two dots in my head, and I verified my suspicions. I was right, as it turns out, our image processing library is compiled against a .Net wrapper against a platform specific DLL targeting the x64 platform. It turns out, his CodeRush test runner was running in 32 bit mode. The fix was a simple one, where he simply had to tell CodeRush to run in x64 mode if the target platform was AnyCPU. The option is fairly obvious, if you know where to look.


Coderush Test RunnerIn order to enable it, bring up the CodeRush options (DevExpress menu –> Options or Ctrl+Alt+Shift+O for the keyboard inclined), expand the "Unit Testing" option folder on the left, and select the "Test Runner" sub-item. In the main window, about half way down, you will see a checkbox marked as "Execute in x64 mode if active configuration is AnyCPU". Check that, click Ok, and you’re set!


It is important to note that the only time this will cause an issue, if you have a library that is explicitly targeting a specific platform. If all of your libraries are targeting AnyCPU, you will not run into a problem, though you probably want to run your tests to where you are targeting both platforms, in case you notice any discrepancies, run into overflows, type incompatibilities, etc. In our case, we have an C++ image processing library that was compiled and linked to target the x64 platform, and as such, will only run in 64 bit mode.