Object reference not set to an instance of an object

Welcome Forums DSC (Desired State Configuration) Object reference not set to an instance of an object

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 8 months ago.

  • Author
    Posts
  • #35396

    Participant
    Points: 0
    Rank: Member

    I have a blank Dsc Class Resource. It always returns $true from the Test method but if I push the config several times in a row I get the error. What on earth could be causing this. It works most of the time but fails randomly.

    [ Start Test ]

    Object reference not set to an instance of an object.
    + CategoryInfo : OperationStopped: (:) [], CimException
    + FullyQualifiedErrorId : System.NullReferenceException
    + PSComputerName : localhost

  • #35406

    Member
    Points: 0
    Rank: Member

    So you just have something like this in your code?

    [bool] Test() { return $true }
    

    If that's the case, then the LCM itself must be failing to create an instance of your class, and this is a bug you should report to Microsoft.

  • #35411

    Participant
    Points: 0
    Rank: Member

    Yes that is exactly what I have in my code, I switched everything to use the script version instead of the class version and I don't get any errors ever. If I use the class version it randomly fails with the error I stated above.

  • #35804

    Participant
    Points: 0
    Rank: Member

    I had this same issue and after restarting the WMI Service i was able to create instances of my DSC classes. This happened even though my LCM was configured for Debug All. Very strange but easy resolution.

The topic ‘Object reference not set to an instance of an object’ is closed to new replies.