Partager via


VS 2017-Invalid class:System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)

Visual Studio 2017 installation fails after extracting files. As per the bootstrapper log:

VisualStudio Bootstrapper:3/28/2017 3:24:41 PM: Current Optin root path does not exists
VisualStudio Bootstrapper:3/28/2017 3:24:42 PM: Caught Exception: Type = ManagementException, Message = Invalid class , StackTrace = at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.Get()
   at Microsoft.VisualStudio.Setup.Bootstrapper.Utilities.GetParentProcess(ILogger logger, Boolean throwOnComException)
VisualStudio Bootstrapper:3/28/2017 3:24:42 PM: Invalid class
VisualStudio Bootstrapper:3/28/2017 3:24:42 PM: Caught Exception: Type = ManagementException, Message = Invalid class , StackTrace =    at Microsoft.VisualStudio.Setup.Bootstrapper.Utilities.GetParentProcess(ILogger logger, Boolean throwOnComException)
   at Microsoft.VisualStudio.Setup.Bootstrapper.Program.Parse(String[] args, ILogger logger, String entryAssemblyProcessName, String entryAssemblyProcessFullName)
   at Microsoft.VisualStudio.Setup.Bootstrapper.Program.Run(String[] args)
VisualStudio Bootstrapper:3/28/2017 3:24:42 PM: General Failure. Message:Invalid class  Callstack:    at Microsoft.VisualStudio.Setup.Bootstrapper.Utilities.GetParentProcess(ILogger logger, Boolean throwOnComException)
   at Microsoft.VisualStudio.Setup.Bootstrapper.Program.Parse(String[] args, ILogger logger, String entryAssemblyProcessName, String entryAssemblyProcessFullName)
   at Microsoft.VisualStudio.Setup.Bootstrapper.Program.Run(String[] args) Inner Message: Internal

I launched the Setup in debugger and captured a crash dump.  I found the following information from the crash dump:
0:000> !pe
Exception object: 0000000002627408
Exception type:   System.Management.ManagementException
Message:          Invalid class
InnerException:   <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131501

0:000> kL100
# Child-SP          RetAddr           Call Site
00 00000000`006fb470 00007fff`f58ffbf1 KERNELBASE!RaiseException+0x68
01 00000000`006fb550 00007fff`f58ff9f0 clr!RaiseTheExceptionInternalOnly+0x2f0
02 00000000`006fb650 00007fff`962248e3 clr!IL_Throw+0x111
03 00000000`006fb800 00007fff`f58ff589 vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.Utilities.GetParentProcess(Microsoft.VisualStudio.Setup.Services.ILogger, Boolean)+0x1e3
04 00000000`006fb850 00007fff`f5900bfb clr!ExceptionTracker::CallHandler+0xf1
05 00000000`006fb940 00007fff`f58fed0f clr!ExceptionTracker::CallCatchHandler+0x8b
06 00000000`006fb9d0 00007ff8`0b1b9b6d clr!ProcessCLRException+0x31c
07 00000000`006fbab0 00007ff8`0b14595c ntdll!RtlpExecuteHandlerForUnwind+0xd
08 00000000`006fbae0 00007fff`f5900e10 ntdll!RtlUnwindEx+0x38c
09 00000000`006fc1c0 00007fff`f5900dcf clr!ClrUnwindEx+0x40
0a 00000000`006fc6e0 00007ff8`0b1b9aed clr!ProcessCLRException+0x2e9
0b 00000000`006fc7c0 00007ff8`0b144fe9 ntdll!RtlpExecuteHandlerForException+0xd
0c 00000000`006fc7f0 00007ff8`0b1b8bfa ntdll!RtlDispatchException+0x3a9
0d 00000000`006fcf00 00007ff8`07be1f28 ntdll!KiUserExceptionDispatch+0x3a
0e 00000000`006fd600 00007fff`f58ffbf1 KERNELBASE!RaiseException+0x68
0f 00000000`006fd6e0 00007fff`f58ff9f0 clr!RaiseTheExceptionInternalOnly+0x2f0
10 00000000`006fd7e0 00007fff`e5e85a69 clr!IL_Throw+0x111
11 00000000`006fd990 00007fff`e5e81b79 System_Management_ni!System.Management.ManagementException.ThrowWithExtendedInfo(System.Management.ManagementStatus)+0xc9
12 00000000`006fd9f0 00007fff`9622478b System_Management_ni!System.Management.ManagementObject.Get()+0x199
13 00000000`006fda80 00007fff`962226a0 vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.Utilities.GetParentProcess(Microsoft.VisualStudio.Setup.Services.ILogger, Boolean)+0x8b
14 00000000`006fdae0 00007fff`961f2751 vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.Program.Parse(System.String[], Microsoft.VisualStudio.Setup.Services.ILogger, System.String, System.String)+0xa0
15 00000000`006fde50 00007fff`961f0514 vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.Program.Run(System.String[])+0x131
16 00000000`006fdf10 00007fff`adfeeece vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.App.OnStartup(System.Windows.StartupEventArgs)+0x34
17 00000000`006fdf40 00007fff`e22f9bc9 PresentationFramework_ni!System.Windows.Application.<.ctor>b__1_0(System.Object)+0x3e
18 00000000`006fdf80 00007fff`e22f9ac6 WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0x69
19 00000000`006fdff0 00007fff`e22fca2b WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x36
1a 00000000`006fe040 00007fff`f439a77e WindowsBase_ni!System.Windows.Threading.DispatcherOperation.InvokeImpl()+0x10b
1b 00000000`006fe0c0 00007fff`f439a617 mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+0x15e
1c 00000000`006fe190 00007fff`f439a5d2 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+0x17
1d 00000000`006fe1c0 00007fff`e2513670 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+0x52
1e 00000000`006fe210 00007fff`e22fc784 WindowsBase_ni!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)+0x80
1f 00000000`006fe270 00007fff`e22f7c24 WindowsBase_ni!System.Windows.Threading.DispatcherOperation.Invoke()+0x64
20 00000000`006fe2d0 00007fff`e22f8061 WindowsBase_ni!System.Windows.Threading.Dispatcher.ProcessQueue()+0x1a4
21 00000000`006fe350 00007fff`e22f9e53 WindowsBase_ni!System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0x71
22 00000000`006fe3d0 00007fff`e22f9d82 WindowsBase_ni!MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0xc3
23 00000000`006fe460 00007fff`e22f9bc9 WindowsBase_ni!MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)+0x82
24 00000000`006fe4b0 00007fff`e22f9ac6 WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0x69
25 00000000`006fe520 00007fff`e22f7583 WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x36
26 00000000`006fe570 00007fff`e22f94ff WindowsBase_ni!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)+0x173
27 00000000`006fe610 00007fff`e24c471a WindowsBase_ni!MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)+0x11f
28 00000000`006fe6c0 00007fff`f5897b9e WindowsBase_ni!DomainBoundILStubClass.IL_STUB_ReversePInvoke(Int64, Int32, Int64, Int64)+0x5a
29 00000000`006fe730 00007ff8`092d1169 clr!UMThunkStub+0x6e
2a 00000000`006fe7c0 00007ff8`092d0c97 user32!UserCallWinProcCheckWow+0x1f9
2b 00000000`006fe8b0 00007fff`e2330ee8 user32!DispatchMessageWorker+0x1a7
2c 00000000`006fe930 00007fff`e230d8fc WindowsBase_ni!DomainBoundILStubClass.IL_STUB_PInvoke(System.Windows.Interop.MSG ByRef)+0x78
2d 00000000`006fe9f0 00007fff`ad6998b3 WindowsBase_ni!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)+0xec
2e 00000000`006fea80 00007fff`ad69969d PresentationFramework_ni!System.Windows.Application.RunDispatcher(System.Object)+0x73
2f 00000000`006feac0 00007fff`961f04b8 PresentationFramework_ni!System.Windows.Application.RunInternal(System.Windows.Window)+0x8d
30 00000000`006feb20 00007fff`f58240b3 vs_setup_bootstrapper!Microsoft.VisualStudio.Setup.Bootstrapper.App.Main()+0x38
31 00000000`006feb50 00007fff`f5823f75 clr!CallDescrWorkerInternal+0x83
32 00000000`006feb90 00007fff`f5824546 clr!CallDescrWorkerWithHandler+0x4e
33 00000000`006febd0 00007fff`f593b6ae clr!MethodDescCallSite::CallTargetWorker+0xf8
34 (Inline Function) ——–`——– clr!MethodDescCallSite::Call+0x1c
35 00000000`006fecd0 00007fff`f593b846 clr!RunMain+0x1e7
36 00000000`006feeb0 00007fff`f593b73e clr!Assembly::ExecuteMainMethod+0xb6
37 00000000`006ff1a0 00007fff`f593b9a3 clr!SystemDomain::ExecuteMainMethod+0x5ea
38 00000000`006ff7d0 00007fff`f593b97a clr!ExecuteEXE+0x3f
39 00000000`006ff840 00007fff`f594dd3c clr!_CorExeMainInternal+0xb2
3a 00000000`006ff8d0 00007fff`f627802d clr!_CorExeMain+0x14
3b 00000000`006ff910 00007fff`f6391184 mscoreei!_CorExeMain+0xe0
3c 00000000`006ff960 00007fff`f63910ab mscoree!ShellShim__CorExeMain+0xb8
3d 00000000`006ff990 00007ff8`088a8102 mscoree!_CorExeMain_Exported+0xb
3e 00000000`006ff9c0 00007ff8`0b16c5b4 kernel32!BaseThreadInitThunk+0x22
3f 00000000`006ff9f0 00000000`00000000 ntdll!RtlUserThreadStart+0x34

As per the error message it appears that the win32_process class is not installed or corrupted on the machine. In order to narrow down the issue we created and execute the C# console application using the steps outline below: 

Create Project:
Create a project (WMITest) which targets 3.5 Framework on a machine that has VS 2015/2017 already installed and build it.

VS_Error

Source Code:
       using System;

using System.Diagnostics;

using System.IO;

using System.Management;

using System.Reflection;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine(“Start”);

            var processName = Assembly.GetEntryAssembly().GetName().Name;

            Console.WriteLine($”Process Name: {processName}“);

 

            var directory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            Console.WriteLine($”Directory Name: {directory}“);

 

            var parentProcessFullPath = GetParentProcess().MainModule.FileName;

            Console.WriteLine(parentProcessFullPath);

 

            Console.WriteLine(“End”);

        }

 

        internal static Process GetParentProcess()

        {

            Console.WriteLine($”Enter GetParentProcess”);

            int Id = Process.GetCurrentProcess().Id;

            Console.WriteLine($”Current ProcessId {Id}“);

            try

            {

                using (ManagementObject mo = new ManagementObject(“win32_process.handle='” + Id + “‘”))

                {

                    mo.Get();

                    Console.WriteLine($”Parent Id: {mo[“ParentProcessId”]}“);

                    int parentPid = Convert.ToInt32(mo[“ParentProcessId”]);

                    Console.WriteLine($”Parent Id (Int): {parentPid}“);

                    return Process.GetProcessById(parentPid);

                }

            }

            catch(Exception ex)

            {

                Console.WriteLine($”Message {ex.Message} Exception {ex.StackTrace}“);

                return null;

            }

        }

    }

}

The output of the above application (WMITest.Exe) execution (run from an admin cmd prompt):

Start
Process Name: WMITest
Directory Name: c:\WMITest\
Enter GetParentProcess
Current ProcessId 1536
Message Invalid class Exception at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.Get()

Here are the steps to resolve the issue (Reference: WMI: Missing or Failing WMI Providers or Invalid WMI Class):

1. Go to start-run and type in wmimgmt.msc
2. Right click on Local Wmi Control (Local)and select properties
3. Click on the Security tab and expand Root folder. This is where you will see all of the namespace listed for WMI
4. Select the cimv2 namespace as pointed below:

 VS_Error

5. If you find the namespace is missing, do the following, otherwise skip to step 6 if the namespace is listed
a. From the command prompt with administrative rights or elevated privileges change directory to C:\Windows\System32\Wbem and run the following command: mofcomp.exe CimWin32.mof
b. For re-registering associated .dll if one exists use following command: regsvr32 CIMWin32.dll
c. Restart the Windows Management Instrumentation Service
d. Go to start-run and type in wmimgmt.msc
e. Right click on Local Wmi Control (Local)and select properties
f. Click on the Security tab and expand Root folder. You can now see cimv2.

6. Create a system restore point (Steps: https://support.microsoft.com/en-us/help/17127/windows-back-up-restore)
7. Execute the console application if there is no error, exit.
a. From the command prompt with administrative rights or elevated privileges, execute the following steps and execute the following this: net stop winmgmt
b. Open a Windows Explorer and locate the path to C:\windows\system32\WBEM\ folder and rename the Repository folder to something else like RepositoryOLD (right click and choose ‘Rename Folder’).
c. restart the computer
d. From the command prompt with administrative rights or elevated privileges, execute the following steps and execute the following this: net stop winmgmt
e. From the command prompt with administrative rights or elevated privileges, execute the following steps and execute the following this: winmgmt /resetRepository
f. restart the computer.

8. Run the c# console app(WMITest.Exe) again. If it executes successfully, then start the VS 2017 Setup. It should resolve the issue.