Return the deserialized object when CIM classes cannot be rehydrated · PowerShell/PowerShell@0c41b87 · GitHub
Skip to content

Commit 0c41b87

Browse files
committed
Return the deserialized object when CIM classes cannot be rehydrated
Deserializing a CIM instance rehydrates its CIM class through the native MI library. Where that library is not available (for example macOS, which ships no libmi), loading CimDeserializer throws DllNotFoundException. RehydrateCimClass only caught CimException, so the whole deserialization failed - e.g. Invoke-Command against a Windows host running any CIM-based cmdlet (Get-StorageQoSFlow, Get-Disk, ...) failed from macOS. Treat an unavailable CIM deserializer like any other rehydration failure: keep the deserialized property bag, as RehydrateCimInstance already does when the class cannot be rehydrated, and remember the failure so the native load is not retried for every object.
1 parent 5d871eb commit 0c41b87

3 files changed

Lines changed: 117 additions & 1 deletion

File tree

‎src/System.Management.Automation/engine/serialization.cs‎

Lines changed: 36 additions & 1 deletion

‎test/powershell/engine/Api/Serialization.Tests.ps1‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,17 @@ Describe "Serialization Tests" -tags "CI" {
102102

103103
SerializeAndDeserialize($versionObject).TestScriptProperty | Should -Be $versionObject.TestScriptProperty
104104
}
105+
106+
It 'Deserializes a CIM instance whether or not its CIM class can be rehydrated' {
107+
# Serialized on Windows with class metadata (__ClassMetadata/MiXml). Where the native MI library is
108+
# available the object is rehydrated into a CimInstance; where it is not (e.g. macOS) the deserialized
109+
# property bag must be returned instead of failing the whole deserialization.
110+
$xml = Get-Content -Raw -Path (Join-Path $PSScriptRoot 'assets' 'CimInstance-Win32_TimeZone.clixml')
111+
112+
$result = [System.Management.Automation.PSSerializer]::Deserialize($xml)
113+
114+
$result.Bias | Should -Be 180
115+
$result.Caption | Should -Not -BeNullOrEmpty
116+
$result.PSTypeNames -match 'Win32_TimeZone' | Should -Not -BeNullOrEmpty
117+
}
105118
}
Lines changed: 68 additions & 0 deletions

0 commit comments

Comments
 (0)