Skip to content

The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception #7051

@genifycom

Description

@genifycom

I am attempting to move a Windows only .Net Core 3.1 application to .Net Core 6.0

In there I am using this statement:

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher($"SELECT CommandLine FROM Win32_Process WHERE ProcessId={current_process.Id}"))

Relevant Packages in use are:

  <ItemGroup>
     <PackageReference Include="System.Management" Version="6.0.0" />
  </ItemGroup>

This gives an error

Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.ManagementPath' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception.
 ---> System.TypeLoadException
   at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointerInternal(IntPtr , Type )
   at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer[TDelegate](IntPtr )
   at System.Management.WmiNetUtilsHelper.LoadDelegate[TDelegate](TDelegate& , IntPtr , String )
   at System.Management.WmiNetUtilsHelper..cctor()
   --- End of inner exception stack trace ---
   at System.Management.MTAHelper.IsNoContextMTA()
   at System.Management.MTAHelper.CreateInMTA(Type )
   at System.Management.ManagementPath.CreateWbemPath(String )
   at System.Management.ManagementPath..ctor(String path)
   at System.Management.ManagementPath..cctor()
   --- End of inner exception stack trace ---
   at System.Management.ManagementPath.get_DefaultPath()
   at System.Management.ManagementScope._Clone(ManagementScope , IdentifierChangedEventHandler )
   at System.Management.ManagementScope._Clone(ManagementScope )
   at System.Management.ManagementObjectSearcher..ctor(ManagementScope , ObjectQuery , EnumerationOptions )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Staleneeds-more-infoNot enough information has been provided. Please share more detail as requested.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions