Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't compile configuration with MOF-based resources when PSDSCv3 is also installed #103

Open
3 tasks done
gaelcolas opened this issue Mar 22, 2023 · 0 comments
Open
3 tasks done
Labels

Comments

@gaelcolas
Copy link
Collaborator

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

With ChocoInstalled.config.ps1 containing this:

Configuration ChocoInstalled {
    Import-DscResource -ModuleName Chocolatey

    node ChocoInstalled {
        ChocolateySoftware chocoSoftwareInstalled {
            Ensure = 'Present'
        }
    }
}

Here's what I tried:

PS C:\src\Chocolatey> get-module PSDesiredStateConfiguration
PS C:\src\Chocolatey> ipmo PSDesiredStateConfiguration -RequiredVersion 2.0.6
PS C:\src\Chocolatey> get-module PSDesiredStateConfiguration

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.0.6                 PSDesiredStateConfiguration         {Configuration, Get-DscResource, Invoke-DscResource, New-Ds…

PS C:\src\Chocolatey> ChocoInstalled -OutputPath .\output\MOFs\
PSDesiredStateConfiguration\node: C:\src\Chocolatey\source\GCPackages\ChocoInstalled\ChocoInstalled.config.ps1:4:5
Line |
   4 |      node ChocoInstalled {
     |      ~~~~
     | The term 'Chocolatey\ChocolateySoftware' is not recognized as a name of a cmdlet, function, script file, or executable
     | program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.    
InvalidOperation: You cannot call a method on a null-valued expression.
PS C:\src\Chocolatey> get-module PSDesiredStateConfiguration

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     3.0.0      beta1      PSDesiredStateConfiguration         {Configuration, ConvertTo-DscJsonSchema, Get-DscResource, I…
Script     2.0.6                 PSDesiredStateConfiguration         {Configuration, Get-DscResource, Invoke-DscResource, New-Ds

As you can see, the 3.0.0-beta1 version is automatically imported, and I suspect that's why compiling the configuration with a MOF-based resource doesn't work.

Compiling a Class based resource does work though.

Expected behavior

PS C:\src\Chocolatey> . .\source\GCPackages\ChocoInstalled\ChocoInstalled.config.ps1
PS C:\src\Chocolatey> ChocoInstalled -OutputPath .\output\MOFs\

    Directory: C:\src\Chocolatey\output\MOFs

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          22/03/2023    14:17            606 ChocoInstalled.mof

Actual behavior

PS C:\src\Chocolatey> ChocoInstalled -OutputPath .\output\MOFs\
PSDesiredStateConfiguration\node: C:\src\Chocolatey\source\GCPackages\ChocoInstalled\ChocoInstalled.config.ps1:4:5
Line |
   4 |      node ChocoInstalled {
     |      ~~~~
     | The term 'Chocolatey\ChocolateySoftware' is not recognized as a name of a cmdlet, function, script file, or executable
     | program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.    
InvalidOperation: You cannot call a method on a null-valued expression.
PS C:\src\Chocolatey> get-module PSDesiredStateConfiguration

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     3.0.0      beta1      PSDesiredStateConfiguration         {Configuration, ConvertTo-DscJsonSchema, Get-DscResource, I…
Script     2.0.6                 PSDesiredStateConfiguration         {Configuration, Get-DscResource, Invoke-DscResource, New-Ds…

Error details

PS C:\src\Chocolatey> get-error

Exception             : 
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : You cannot call a method on a null-valued expression.
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvokeMethodOnNull
        InvocationInfo        : 
            ScriptLineNumber : 2751
            OffsetInLine     : 20
            HistoryId        : -1
            ScriptName       : 
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1
            Line             : if($nodeDoc.Contains("PsDscRunAsCredential"))

            PositionMessage  : At
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1:2751 char:20   
                               +                 if($nodeDoc.Contains("PsDscRunAsCredential"))
                               +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0
            PSCommandPath    : 
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Write-NodeMOFFile,
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1: line 2751     
                                at Configuration,
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1: line 2205     
                                at <ScriptBlock>, C:\src\Chocolatey\source\GCPackages\ChocoInstalled\ChocoInstalled.config.ps1:   
line 1
                                at <ScriptBlock>, <No file>: line 1
    TargetSite  : 
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.3.2.500,       
Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : You cannot call a method on a null-valued expression.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  : 
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)   
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
InvocationInfo        : 
    ScriptLineNumber : 2751
    OffsetInLine     : 20
    HistoryId        : -1
    ScriptName       : 
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1
    Line             : if($nodeDoc.Contains("PsDscRunAsCredential"))

    PositionMessage  : At
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1:2751 char:20   
                       +                 if($nodeDoc.Contains("PsDscRunAsCredential"))
                       +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0
    PSCommandPath    : 
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1
    CommandOrigin    : Internal
ScriptStackTrace      : at Write-NodeMOFFile,
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1: line 2751     
                        at Configuration,
C:\Users\GaelColas\Documents\PowerShell\Modules\PSDesiredStateConfiguration\3.0.0\PSDesiredStateConfiguration.psm1: line 2205     
                        at <ScriptBlock>, C:\src\Chocolatey\source\GCPackages\ChocoInstalled\ChocoInstalled.config.ps1: line 1    
                        at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

notcrescendo

Visuals

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant