Search code examples
c#wmi

System.InvalidProgramException Error C# when creating CIMSession


Trying to remotly connect to another PC's WMI but when creating the CimSession I get the following error

System.InvalidProgramException:'Common Launguage Runtime detexted an invalid program'

The code I am running is as follows

using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;


namespace SMAPIQuery
{
    class Program
    {
        static void Main()
        {
            string computer = "ComputerB";
            DComSessionOptions DComOptions = new DComSessionOptions();
            DComOptions.Impersonation = ImpersonationType.Impersonate;
            CimSession Session = CimSession.Create(computer, DComOptions);
        }
    }
}

Unsure as to what throws this error or how to get around it


Solution

  • The issue was I was using .Net Core and not .Net Framework