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

ParameterBindingValidationException exception thrown when $PSUICulture not en-US #382

Open
stuart938503 opened this issue Nov 1, 2021 · 1 comment · May be fixed by #383
Open

ParameterBindingValidationException exception thrown when $PSUICulture not en-US #382

stuart938503 opened this issue Nov 1, 2021 · 1 comment · May be fixed by #383
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@stuart938503
Copy link
Contributor

Prelims:

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS C:\Windows\system32> [environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19043  0
PS C:\Windows\system32> Get-Module -Name LabBuilder

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.2.0      LabBuilder                          {Connect-LabVM, Disconnect-LabVM, Get-Lab, Get-LabResourceISO...}

On installing the above version of LabBuilder and trying to Install-Lab, a ParameterBindingValidationException exception is thrown:

PS C:\Windows\system32> Install-Lab -ConfigPath D:\VMs\Labs\MIM1\Configuration.xml -Verbose
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'True'; IsRegistered = 'True'.
Write-LabMessage : Cannot validate argument on parameter 'Message'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Program Files\WindowsPowerShell\Modules\LabBuilder\1.2.0\LabBuilder.psm1:9729 char:35
+ ... te-LabMessage -Message $($LocalizedData.InitializingLabFoldersMesage)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Write-LabMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Write-LabMessage

<lines omitted for brevity - all related to the above>

Inspecting LabBuilder.psm1, it appears $LocalizedData is not set. It should be set under lines 11-31:

#region LocalizedData
$culture = $PSUICulture

if ([System.String]::IsNullOrEmpty($culture))
{
    $culture = 'en-US'
}
else
{
    if (Test-Path -Path (Join-Path -Path $script:LabBuidlerModuleRoot -ChildPath $culture))
    {
        $culture = 'en-US'
    }
}

Import-LocalizedData `
    -BindingVariable LocalizedData `
    -Filename 'LabBuilder.strings.psd1' `
    -BaseDirectory $script:LabBuidlerModuleRoot `
    -UICulture $culture
#endregion

This should set $culture to en-US if $PSUICulture is empty, or if a path does not exist for the local culture data. This fails however as the Test-Path if statement will only set it to en-US if the path exists. I believe the result of Test-Path should be negated.

My own culture is:

PS C:\Windows\system32> $PSUICulture
en-GB
stuart938503 pushed a commit to stuart938503/LabBuilder that referenced this issue Nov 1, 2021
@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Nov 1, 2021
@PlagueHO
Copy link
Owner

PlagueHO commented Nov 1, 2021

IIRC we found similar problem in DSCResource.Common - so should probably copy this function across from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants