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

Get-LocalizedData: Fails to find *.strings.psd1 when DefaultUICulture not specified #37

Closed
PlagueHO opened this issue May 13, 2020 · 10 comments · Fixed by #109
Closed
Assignees
Labels
bug The issue is a bug.

Comments

@PlagueHO
Copy link
Member

Details of the scenario you tried and the problem that is occurring

When using Get-LocalizedData without specifying the -DefaultUICulture parameter an error occurs:

    PSInvalidOperationException: Cannot find the Windows PowerShell data file 'DSC_Computer.psd1' in directory 'D:\a\1\s\output\ComputerManagementDsc\8.2.1\DSCResources\DSC_Computer\en-US\', or in any parent culture directories.
    at Get-LocalizedData<Process>, D:\a\1\s\output\ComputerManagementDsc\8.2.1\Modules\DscResource.Common\0.8.0\DscResource.Common.psm1: line 656

Steps to reproduce the problem

Change any module to use:

$script:localizedData = Get-LocalizedData

when the localized data file is in the en-US folder and named *.strings.psd1.

Expected behavior

It to load the *.strings.psd1 file into the $script:localizedData variable.

Current behavior

Exception is thrown.

    PSInvalidOperationException: Cannot find the Windows PowerShell data file 'DSC_Computer.psd1' in directory 'D:\a\1\s\output\ComputerManagementDsc\8.2.1\DSCResources\DSC_Computer\en-US\', or in any parent culture directories.
    at Get-LocalizedData<Process>, D:\a\1\s\output\ComputerManagementDsc\8.2.1\Modules\DscResource.Common\0.8.0\DscResource.Common.psm1: line 656

Suggested solution to the issue

I'll submit a PR to fix this.

The operating system the target node is running

Windows Server (various versions).

Version and build of PowerShell the target node is running

PS 5.1

Version of the module that was used

Latest.

@PlagueHO PlagueHO self-assigned this May 13, 2020
@PlagueHO PlagueHO added bug The issue is a bug. in progress The issue is being actively worked on by someone. labels May 13, 2020
@PlagueHO
Copy link
Member Author

PlagueHO commented May 14, 2020

I propose we redesign this function to:

  1. Assemble a prioritized list of folders to check for strings files in
  2. Scan each folder for either a .psd1 or .strings.psd1 file
  3. If a file is found, use that folder/culture.
  4. If no file was found in any of the folders then throw an exception.

We should build the list of prioritized folders to scan like this:

  1. UICulture parameter (if specified) - e.g. fr-FR
  2. UICulture - just language (if specified) - e.g. fr
  3. Get-UICulture - e.g. fr-FR
  4. Get-UICulture - just language - e.g. fr
  5. DefaultUICulture - e.g. fr-FR
  6. DefaultUICulture - just language - e.g. fr

@PlagueHO
Copy link
Member Author

@johlju - I'm going to get to work on this one over this weekend. Can you tell me if you think the logic above is OK?

@johlju
Copy link
Member

johlju commented Jul 17, 2020

That looks okay to me.

@johlju
Copy link
Member

johlju commented Jul 20, 2020

I have sent in a PR #51 that resolves issue #50, issue #11, and probably this too, ...but it is very much spagehetti-code at this point. @PlagueHO A refactor according to your suggestion above would be much better! So see the PR #51 as functionality that need to be supported in the refactor, rather than merge it. 🙂

@johlju
Copy link
Member

johlju commented Jul 21, 2020

To clarify my comment above, we keep this issue open to track the very needed refactor of Get-LocalizedData. 🙂

@lbrauns

This comment was marked as off-topic.

@johlju johlju added help wanted The issue is up for grabs for anyone in the community. and removed in progress The issue is being actively worked on by someone. labels Jan 14, 2024
@lbrauns
Copy link

lbrauns commented Jan 20, 2024

I'll add my current progress for documentation.

Blue shell shows the execution of the deployment including the error record.
VSCodium in the background is at a Breakpoint after the execution of Import-LocalizedData @PSBoundParameters.

Get-LocalizedData was altered to write values of $PSBoundParameter to debug and the steppable Pipeline was replaced with a regular call of the Cmdlet.

In the debug shell I executed Import-LocalizedData while manually giving the arguments contained in $PSBoundParameters (visible in Variables section of VSCodium and in the debug output in the blue shell).

Manually running the command is successful, from the module it fails.

image

Error Record:

DEBUG: GET-LOCALIZED: PSBoundParam is null : False
DEBUG: GET-LOCALIZED: PSBoundParam Keys:FileName BaseDirectory
DEBUG: PARAM: FileName = DscResource.Common.strings.psd1
DEBUG: PARAM: BaseDirectory = C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\Modules\DscResource.Common\0.16.0
Import-LocalizedData : Cannot find the Windows PowerShell data file 'DscResource.Common.strings.psd1' in directory
'C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\Modules\DscResource.Common\0.16.0\en\', or in any parent
culture directories.
At
C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\Modules\DscResource.Common\0.16.0\DscResource.Common.psm1:2616
char:13
+             Import-LocalizedData @PSBoundParameters
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\lb\Des...on.strings.psd1:String) [Import-LocalizedData], PSInv
   alidOperationException
    + FullyQualifiedErrorId : ImportLocalizedData,Microsoft.PowerShell.Commands.ImportLocalizedData

@johlju
Copy link
Member

johlju commented Jan 20, 2024

This is very strange. I wonder if the Sysinternals tool DiskMon can show us more what happening in the background when accessing the file - if that can say why it can't import.

I have made a refactor of Get-LocalizationData that I will send in as a PR shortly, it just removes the pipeline and adds extra debugging messages. Probably nothing that solves this one yet though.

@johlju
Copy link
Member

johlju commented Jan 20, 2024

@lbrauns can you please run the new built code in the PR to see if it does anything to help?

You find the code in the artifact output here, under the folder builtModule: https://dev.azure.com/dsccommunity/DscResource.Common/_build/results?buildId=8498&view=artifacts&pathAsName=false&type=publishedArtifacts

You should just need to replace the code inside your copy of HyperVDsc module.

@lbrauns
Copy link

lbrauns commented Jan 20, 2024

You fixed it :)

Debug Output:

VERBOSE: Loading module from path
'C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\Modules\DscResource.Common\0.16.1\DscResource.Common.psd1'.
VERBOSE: Importing function 'Assert-BoundParameter'.
VERBOSE: Importing function 'Assert-ElevatedUser'.
VERBOSE: Importing function 'Assert-IPAddress'.
VERBOSE: Importing function 'Assert-Module'.
VERBOSE: Importing function 'Compare-DscParameterState'.
VERBOSE: Importing function 'Compare-ResourcePropertyState'.
VERBOSE: Importing function 'ConvertFrom-DscResourceInstance'.
VERBOSE: Importing function 'ConvertTo-CimInstance'.
VERBOSE: Importing function 'ConvertTo-HashTable'.
VERBOSE: Importing function 'Find-Certificate'.
VERBOSE: Importing function 'Get-ComputerName'.
VERBOSE: Importing function 'Get-DscProperty'.
VERBOSE: Importing function 'Get-EnvironmentVariable'.
VERBOSE: Importing function 'Get-LocalizedData'.
VERBOSE: Importing function 'Get-LocalizedDataForInvariantCulture'.
VERBOSE: Importing function 'Get-PSModulePath'.
VERBOSE: Importing function 'Get-TemporaryFolder'.
VERBOSE: Importing function 'New-InvalidArgumentException'.
VERBOSE: Importing function 'New-InvalidDataException'.
VERBOSE: Importing function 'New-InvalidOperationException'.
VERBOSE: Importing function 'New-InvalidResultException'.
VERBOSE: Importing function 'New-NotImplementedException'.
VERBOSE: Importing function 'New-ObjectNotFoundException'.
VERBOSE: Importing function 'Remove-CommonParameter'.
VERBOSE: Importing function 'Set-DscMachineRebootRequired'.
VERBOSE: Importing function 'Set-PSModulePath'.
VERBOSE: Importing function 'Test-AccountRequirePassword'.
VERBOSE: Importing function 'Test-DscParameterState'.
VERBOSE: Importing function 'Test-DscProperty'.
VERBOSE: Importing function 'Test-IsNanoServer'.
VERBOSE: Importing function 'Test-IsNumericType'.
DEBUG: Looking for resolved file with base name: 'DSC_VMNetworkAdapter'.
DEBUG: Using specified culture:

LCID             Name             DisplayName

----             ----             -----------

1033             en-US            English (United States)



DEBUG: Looking for Localized data file using the current culture 'en-US'.
DEBUG: File
'C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\DSCResources\DSC_VMNetworkAdapter\en-US\DSC_VMNetworkAdapter.p
sd1' not found.
DEBUG: Found
'C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\DSCResources\DSC_VMNetworkAdapter\en-US\DSC_VMNetworkAdapter.s
trings.psd1'.
DEBUG: Calling Microsoft.PowerShell.Utility\Import-LocalizedData using parameters:
Key           Value
---           -----
UICulture     en-US
FileName      DSC_VMNetworkAdapter.strings.psd1
BaseDirectory C:\Users\lb\Desktop\Dbg_Lability\DSCResources\HyperVDsc\DSCResources\DSC_VMNetworkAdapter


DEBUG: Returning localized data.
VERBOSE: Exporting function 'Get-TargetResource'.
VERBOSE: Exporting function 'Set-TargetResource'.
VERBOSE: Exporting function 'Test-TargetResource'.
DEBUG: Invoking command 'Test-VMNetworkAdapterTargetResource'.

@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Jan 20, 2024
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants