Getting WebDev.WebHost to work on 64 bit Windows
In the past I wrote on how we are doing integration testing of a web services using the WebDev.WebHost assembly. This technique has found its way into Dovetail Seeker and is really handy to do an end to end test against a live web server. I ran into trouble running the tests now that I am running a 64bit OS.
You get this error when trying to spin up the test web server:
An attempt was made to load a program with an incorrect format.
It turns out the WebDev.WebHost assembly is flagged as a 32bit which forces it to be run only within a 32bit version of the framework. In my build automation nunitconsole.exe is the test runner and it is likely flagged as Any CPU and thus running in 64bit mode by default. After checking out Scott Hanselman’s post on 32bitness and 64bitness which does a better job than I am of explaining what is going on here. I was lucky to Google up this helpful post from Dean Harding –64-bit WebDev.WebServer.exe where he basically solves this problem by dissembling and rebuilding the assembly with the 32bit flag off.
Any CPU-izing the assembly
This was a little tricky to accomplish so I thought I would share what it took to make this happen. There are likely some legal issues with doing this so please consider this recipe as simply a guide to getting fair use out of your tests on a 64 bit OS.
- Grab the WebDev.WebHost.dll assembly out of the GAC.
- Grab a copy of Lutz Roeder’s Reflector and the Reflector File DissemblerAdd-in that I found on CodePlex.
- Setup the file dissembler plugin in Reflector as an Add-On.
- Open up the WebDev.WebHost assembly in Reflector. Right Click on the assembly and select Export and select the directory to receive the dissembled code.
- Open up a new blank solution and add the project
- Remove the code signing attributes form the AssemblyInfo.cs
- There are a few small code changes to the code that gets created that I had to make to get VS.Net 2008 to build the dissembled project.
- Request.cs line 409 needs to cast the parameter to IndexOf as a char
- Ntlm.cs lines 61, 63, 65 need the (void*) cast and surrounding parens removed to avoid a CS0212 error. These should look something like – “fixed (void* voidRefX = &variable)”
- Make sure you have Any CPU selected.
- Build the project.
Once the rebuilt version of WebDev.WebHost for Any CPU was dropped into my project’s lib directory everything worked fine. We will not be shipping a copy of the recompiled WebDev.WebHost assembly to anyone and it is only used during integration testing.
Is there a better way?
I feel dirty and a bit wrong dissembling the assembly to get my tests working. I am simply doing this because to the best of my knowledge this is the only way to get this working on a 64bit OS. I will not be shipping a copy of the recompiled WebDev.WebHost assembly to anyone and it is only used during integration testing and not by anything in production.