Friday, July 24, 2009

Visual Studio 2008 and Manifests

Try this with VS2008 (professional edition):

-Create an empty project which will use MFC as a shared dll
- Try to debug into it
-> I bet you will end up seeing a popup that complains that 'MFC90ud.dll not found'.

Now before you figure out where to locate these dlls on your system (they are in the VS2008 redistributable package, typically here: C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\Debug_NonRedist\x86), let me tell you will be wasting 10 more minutes copying these files over to your project's target folder locally. This is what will happen:

[1] You copy the debug dlls into your target folder. Your program still complains.. now a bit later.. when checking for CRT/MFC dll's manifest's context sanity, exactly here in crtlib.c (line 544):

/* check condition (4) */
{
ACTCTX_SECTION_KEYED_DATA askd = { sizeof(askd) };
if (!(*pfnFindActCtxSectionStringW)(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, _CRT_DLL_FILENAME, &askd))
{
/* no activation context used to load CRT DLL, means no manifest present in the process */
return FALSE;
}
}


[2] Now you are baffled! You gave the debugger what it asked for.. and now it throws an assertion with no more useful information that would ease your pain. Ok, you may try to put these debug dlls in the system path, hoping they will load fine when they are in similar company. So you put them in C:/Windows/System32. Happy? A little too soon to be that, my friend. You will see another assertion from the same file as in [1] above BECAUSE God forbid, you tried to copy a redistributable dll into Microsoft's system folder!! :-)

[3] Ok, by now, you have lost all patience, and are back to your trusted friend (no sarcasm here) : Google. You come across a nice post, then another, then another, on the same issues, and all Microsoft MVPs on vacation I guess, all dumb with no solution.. until you come across this nice guy who figured out a solution: http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/2d6af19a-6ead-4c00-a896-871a28c5f7f1.

The asnwer is, DONT trust Microsoft to create manifests and match them correctly for you. DO IT yourself, explicitly, by incorporating the manifests of Microsoft debug dlls into your program this way in the manifest tool -> command line text box:

-outputresource:".\Debug\MyProgramName.exe"

So in the end, you paid huge for a supposedly reputed Microsoft program suite, and who helped you in the end, a free search engine.

Lesson learnt, Capitalism!!!

No comments:

Post a Comment

Thank you for leaving a comment on my blog. Please feel free to share any information you find relevant here.