none
CimSession generate InvalidProgramException

    Question

  • Hey everyone

    Is there someone that can explain why my code generate the Exception? I've tried lots of variations, but all seems to generate the same Exception. I borrowed this code from MSDN (https://msdn.microsoft.com/en-us/library/mt703458(v=vs.85).aspx)

    using System;
    using System.Text;
    using System.Threading;
    using Microsoft.Management.Infrastructure;
    
    namespace CimSessionNs
    {
        class Program
        {
            static void Main(string[] args)
            {
                // this line throw the exception
                CimSession mySession = CimSession.Create("localhost");
            }
        }
    }

    Monday, April 10, 2017 6:00 AM

Answers

  • I found the problem. On Windows 7 you need to update/install Windows Management. It doesn't matter if windows.management.dll in on the system, you still need to update Windows Management.
    • Marked as answer by PL73 Monday, April 10, 2017 11:43 AM
    Monday, April 10, 2017 11:43 AM

All replies

  • Try passing in name of your computer alongwith session options

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, April 10, 2017 6:13 AM
  • Good idea, but I've already tried that. 

    Doesn't seem to matter what I try, so I'm thinking it may have something to do with COM/DCOM settings or that I'm missing something on the computer. 

    Any more ideas?

    Monday, April 10, 2017 8:05 AM
  • I found the problem. On Windows 7 you need to update/install Windows Management. It doesn't matter if windows.management.dll in on the system, you still need to update Windows Management.
    • Marked as answer by PL73 Monday, April 10, 2017 11:43 AM
    Monday, April 10, 2017 11:43 AM
  • PL73,

               That's great you posted the solution as well, letting other users/viewers to know the issue and it's solution in future.


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Tuesday, April 11, 2017 4:34 AM
  • Don't waste people's time on wild guesses. This is complete garbage. You have no clue what's causing the issue. 
    Wednesday, March 7, 2018 8:15 PM