From d3625f76622aad2a17acf4635997a20c79d8ecb3 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Wed, 3 Aug 2016 21:04:53 -0700 Subject: [PATCH] Resolving issue with Registry reads where values are not present. --- .../engine/PropertyAccessor.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index db8c8147a..b28809dc2 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -762,19 +762,21 @@ namespace System.Management.Automation return null; } - // verify the value kind as a string - RegistryValueKind kind = regKey.GetValueKind(valueName); + object regValue = regKey.GetValue(valueName); + if (null != regValue) + { + // verify the value kind as a string + RegistryValueKind kind = regKey.GetValueKind(valueName); - if (kind == RegistryValueKind.ExpandString || - kind == RegistryValueKind.String) - { - return regKey.GetValue(valueName) as string; - } - else - { - // The function expected a string, but got another type. This is a coding error or a registry key typing error. - return null; + if (kind == RegistryValueKind.ExpandString || + kind == RegistryValueKind.String) + { + return regValue as string; + } } + + // The function expected a string, but got another type or the value doesn't exist. + return null; } }