Windows – Recurring crash: “An unhandled win32 exception occurred in mscorsvw.exe”. How to diagnose/fix

.net frameworkcrashdebugngenwindows xp

I recently got a new PC at work and had to reinstall development tools, etc. The PC runs Windows XP (blech), and I've got Visual Studio 2010 and .NET Frameworks 2.0, 3.5, and 4.0 installed, each with all current service packs and patches. Windows XP itself is also up-to-date (if one could say that 🙂

One recurring problem I've noticed is the following dialog, which tends to pop up after the machine has been idle for a bit:

Visual Studio Just-In-Time Debugger: An unhandled win32 exception occurred in mscorsvw.exe ... Do you want to debug using the selected debugger?

I suspect the crash is due to the .NET Framework performing Ngen compilation of system assemblies in the background, and crashing when it reaches one assembly in particular.

I've found another mention of this problem at the MSDN forums, and one of the suggested workarounds is to configure Windows XP's Data Execution Prevention feature to "Turn on DEP for essential Windows programs and services only". However, that's already the setting in effect on my PC.

How can I diagnose further? When I try to attach to the process, it's already gone.

Are there any other suggested or likely fixes?


I found some more information on ngen here and here.

I ran the following at a Command Prompt: ngen executequeueditems .. this now lets me reliably reproduce the problem instead of waiting for the idle background ngen to execute.

So, when ngen.exe got to the following entry:

Compiling assembly Microsoft.SqlServer.Management.MultiServerConnection, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91 (CLR v2.0.50727) ...
WARNING: Cannot hardbind to mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 because dependency does not have a native image (check FusLogVw for reason)
Failed to generate native code for dependent image Microsoft.SqlServer.Management.MultiServerConnection, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91 because of the following error: The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

… the result was the following error dialog:

.NET Runtime Optimization Service has encountered a problem and needs to close.

Whereas, other assemblies that failed native image generation didn't actually cause a crash, just an error message.

So, the specific assembly this is failing on is: Microsoft.SqlServer.Management.MultiServerConnection.

What else can I do? I don't particularly care if it can be ngen'd or not at this point; I simply want to stop this annoying recurring error dialog from above. I already tried:

ngen uninstall Microsoft.SqlServer.Management.MultiServerConnection,

… but it says "ERROR: The specified assembly is not installed."

Is there a way to remove an assembly from the ngen queue, so ngen won't even try to generate a native image for it?

Best Answer

  • The nGen of the Sql Server assembly is failing because a previous attempt at nGening the .Net Framework 2.0 mscorlib assembly has failed. This is nothing to do with .Net 4 at all so I suggest you stop looking at it's ngen service (2 and 4 use their own services).

    As for why that's failed - well there's not a huge amount around on the net about this. I did find this on MSDN forums though - there's something in there about confirming whether mscorlib has been correctly nGen'd - I'd check that out.

    Interestingly Sql Server is mentioned on that thread too; although it's 2005 and I think version 10 assemblies you're talking about here are Sql 2008. Still, might provide something.

    But ultimately if this were my machine I would:

    • Uninstall .Net 2.0 and 3.0 and 3.5 (if you're feeling brave uninstall 4.0 as well)

    • Uninstall whatever Sql Server component it is that contains the assembly that's failing the nGen.

    • Install the .Net 3.5 sp1 redist; making sure you have also got the hotfix that is referenced for further down the page as well.

    • Wait for all the nGening to complete before continuing.

    • If you uninstalled .Net 4 reinstall that now too.

    • Reinstall the Sql Server component removed in step 2.

    Yes, I know, kinda a 'switch it off and on again' answer - but I think it's better than trying to sidestep the issue. If mscorlib 2.0 has not nGen'd correctly then tbh .Net 2.0 is not really usable in its current state. And since this is a SQL Server component that's trying to nGen - only an nGen'd mscorlib v2 will work with it (nGen'd mscorlib v4 will not).

  • Related Question