Dec 27, 2010

Visual Studio 2008/2010 C++ Compiler Bug

I recently had an unpleasant experience with both the VS2008 C++ compiler and the support offered by the Microsoft forums. I decided to add some named pipe code to my project so I added a reference to System.Core. Before adding any additional code I recompiled my project and was surprised to get: C1001: An internal error has occurred in the compiler and a dialog that stated "Microsoft (R) C/C++ Optimizing Compiler has stopped working ... " and a Close program button.  Part of the unpleasantness was the lack of being taken seriously by the Microsoft Moderator on the VCLanguage forum where I started a thread seeking help.. I came up with an extremely simple, extremely reliable way to reproduce the bug in six steps. Here is verbatim what I put on the forum (you can see if your installation has the problem too):

  1. Create a new System Console CLR project in C++
  2. Add a reference to System.Core
  3. Set Create/Use Precompiled Header to "Not Using Precompiled Headers" -IMPORTANT
  4. Add the following code and hit CTRL-F7 - The compiler crashes.
  5. Comment out the Line that starts with String^
  6. Hit CTRL-F7 the code compiles.
#include "stdafx.h"

using namespace System;
using namespace System::IO;
using namespace System::IO::Pipes;

int main(array<System::String ^> ^args)
NamedPipeServerStream^ pipe_stream = gcnew NamedPipeServerStream("test",PipeDirection::InOut);
String^ msg = String::Format("This will cause the compiler to crash {0} when System.Core is referenced",1);
Console::WriteLine(L"Hello World");
return 0;
Really it’s only four steps as steps 5 and 6 just prove that without a String^ the problem goes away. Microsoft’s response was that they couldn’t replicate the problem. I began to suspect the Microsoft Moderator assigned to my issue has what I call the Henry Kissinger complex.

There’s an old story  about a new intern at the White House that worked for Henry Kissinger. Kissinger asked the intern for a report on a developing crisis. The intern, excited by the chance, whipped together the report and put it on Kissinger’s desk. The next day it came back with a note “You can do better”. The intern a little crushed, went back and reworked the report adding supporting references and opposing viewpoints. He put the back on Kissinger’s desk only to get it back the next day with “You can still do better.” This went on for several more days at which point the intern was convinced he had done everything he possibly could and the report just couldn’t be improved. He decided to hand carry it to Mr. Kissinger, whereupon he explained that this version was the absolute best he could do. At which point Mr. Kissinger replied, “fine, in that case now I’ll read it.”

A month after reporting the problem and “rewriting the report” for the amusement of the Microsoft Moderator I finally started another thread and asked the forum members to please help and try to duplicate the bug.It took six minutes, to get a positive response from a user. Within the hour I had multiple responses, everyone indicating they had no problem duplicating the bug on VS2008 or VS2010 and in multiple operating systems. Within a day of getting all these positive duplications, the Microsoft Moderator decided to “actually read it” and reported that lo and behold he could replicate the bug after all. In the meantime another user had already directed me to for reporting the bug. It turns a hotfix for another problem also fixed the bug I found.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.