From e213d45bc97c670f3fab62463980807a9e4c5aca Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Sat, 5 May 2018 22:07:51 +0100 Subject: [PATCH] Fix NullReferenceException when CimSuperClass is null and remove empty catch block. --- Rules/UseIdenticalMandatoryParametersDSC.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Rules/UseIdenticalMandatoryParametersDSC.cs b/Rules/UseIdenticalMandatoryParametersDSC.cs index 73f37645f..a4c1c3974 100644 --- a/Rules/UseIdenticalMandatoryParametersDSC.cs +++ b/Rules/UseIdenticalMandatoryParametersDSC.cs @@ -241,25 +241,17 @@ private IDictionary GetKeys(string fileName) var errors = new System.Collections.ObjectModel.Collection(); var keys = new List(); List cimClasses = null; - try + if (!isDSCClassCacheInitialized) { - if (!isDSCClassCacheInitialized) - { - DscClassCache.Initialize(); - isDSCClassCacheInitialized = true; - } - - cimClasses = dscClassImporter(mofFilepath, moduleInfo, errors); - } - catch - { - // todo log the error + DscClassCache.Initialize(); + isDSCClassCacheInitialized = true; } + cimClasses = dscClassImporter(mofFilepath, moduleInfo, errors); + var cimClass = cimClasses?.FirstOrDefault(); var cimSuperClassProperties = new HashSet( - cimClass?.CimSuperClass.CimClassProperties.Select(p => p.Name) ?? - Enumerable.Empty()); + cimClass.CimSuperClass != null ? cimClass.CimSuperClass.CimClassProperties.Select(p => p.Name) : Enumerable.Empty()); return cimClass? .CimClassProperties?