Skip to content

[Bug]: GetHypervState "Class not registered" error not caught on non-English Windows locales #4153

Description

@ctm-fl

BCContainerhelper version

6.1.14

Describe the issue

The fix for #3378 (PR #3382) added a try/catch in GetHypervState that checks for the error message "Class not registered". However, on non-English Windows installations (e.g. German), the error message is localized (e.g. "Klasse nicht registriert"). The regex match $_.Exception.Message -match "Class not registered" does not match the localized string, so the error is re-thrown instead of being caught gracefully.

This causes New-BcContainer to fail with Error: Klasse nicht registriert when running as administrator on a German Windows system with PowerShell 7.

(Disclaimer: I used AI to create the text for this bug report.)

Command or script used to produce the issue

Any call to New-BcContainer while running as administrator on a non-English Windows with PowerShell 7, e.g.:

New-BcContainer -accept_eula -containerName "test" -artifactUrl (Get-BCArtifactUrl -type OnPrem -version 27.1 -country de)

Full output of the command or script

BcContainerHelper is version 6.1.14
BcContainerHelper is running as administrator
Error: Klasse nicht registriert

Stacktrace: at GetHypervState, C:\ProgramData\BcContainerHelper\6.1.14\BcContainerHelper\BcContainerHelper.psm1: line 38
at New-BcContainer, C:\ProgramData\BcContainerHelper\6.1.14\BcContainerHelper\ContainerHandling\New-NavContainer.ps1: line 437

Additional information

The current code in BcContainerHelper.psm1 line 47:

if ($_.Exception.Message -match "Class not registered") {

A simple fix would be to also match common localized variants, or better yet, match the HResult or exception type instead of the message string. For example:

if ($_.Exception.Message -match "Class not registered|Klasse nicht registriert") {

Or more robust, matching the HRESULT 0x80040154 (REGDB_E_CLASSNOTREG):

  • OS: Windows 11 (German locale)
  • PowerShell: 7.x
  • Hyper-V: Fully installed and enabled, vmms service running

Does this happen every time?

Yes

Did this used to work?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions