Wednesday, June 21, 2006
« June 2006 Geek Dinner - June 29th, 2006 | Main | Service-Oriented Architecture Presentati... »

I was performing some routine debugging today and suddenly received a very strange error; one that I had not heretofore received:

Error while trying to run project: Could not load file or assembly 'TestApplication' or one of its dependencies. The module was expected to contain an assembly manifest.

When I attempted to run the application from Explorer I was greeted with the message:

C:\SomeBuildDirectory\TESTAP~2.EXE
The NTVDM CPU has encountered an illegal instruction.
CS:0e1b IP:0173 OP:65 63 74 69 6f Choose 'Close' to terminate the application.

Needless to day, I was a bit disconcerted.  I started to dig into to see what the problem was.

The very first thing I did was Google it.  The search yielded a page that seemed to fit the bill exactly.  A user by the name of PCarrier had experienced a very similar problem.  He had developed an application in C# and was getting the same result.  As it turns out, he had a virus.  Well, that was a possibility here, but I doubted it at first.  However, I decided to see for myself what was going on.

The next thing I did was investigate my Post-Build actions - this solution has several projects each of which has its own custom Post-Build action.  Nothing seemed out of place.

I then investigated the directory system.  I noticed was that in my \obj directory, the output .exe file was the proper 13K but in the \bin directory it was 6K.  The file was being truncated!

Therefore, I opened up FileMon and started monitoring for changes to that file and sure enough I saw some very erratic behavior.  It looked strange.  Several accesses to the file in the \obj folder were correct and they allocated the file properly but when it came time to write it to the \bin folder it looked like there was some ADS (Alternate Data Stream) stuff going on which was truncating the file to it's 6K size.

I started to suspect virus so I installed the AV software (yes, I didn't have any AV software running at this juncture) and ran a scan.  Nothing turned up.  I then ran the RootkitRevealer to see if anything cropped up there - nothing out of the ordinary.  Well, that was putting my mind at ease, but I was still facing the same problem.

Strangely, after doing the AV scan and Rootkit detection the ADS activity ceased.

I decided to retrace my steps to see if anything was amiss and started again to investigate the Post-Build actions and then (finally!) something stood out at me.  I had edited the macro to copy a shared configuration file and rather than copy the file to the target directory, I had mistakenly copied the configuration file to the target path (which includes the output .exe name)

The command I had was

copy $(SolutionDir)SharedConfiguration.config $(TargetPath)

And it should have been

copy $(SolutionDir)SharedConfiguration.config $(TargetDir)

Sometimes the little things get you.  I'm thankful that it was such a simple thing and that viruses didn't enter the picture, but I kick myself that I didn't suspect that the .exe file wasn't a valid one to begin with.  I should have opened the .exe in Notepad2 and the problem would have been clear from the start.

...but I can now rest at ease.