From 473f09bcb9db0d9e799b96a2daaf136ea7822824 Mon Sep 17 00:00:00 2001 From: Rafael Sliveira Cordeiro Date: Tue, 5 Dec 2023 21:13:14 -0800 Subject: [PATCH] Check and ignoring nulls when using reflection. --- .../Widgets/Exceptions/ExceptionFormatter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs index 97acddf7b..64a0f93f2 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs @@ -303,15 +303,16 @@ private static bool TryGetTupleName(ParameterInfo parameter, Type parameterType, .FirstOrDefault(a => { var attributeType = a.GetType(); - return attributeType.Namespace == "System.Runtime.CompilerServices" && + return attributeType != null && + attributeType.Namespace == "System.Runtime.CompilerServices" && attributeType.Name == "TupleElementNamesAttribute"; }); if (tupleNameAttribute != null) { var propertyInfo = tupleNameAttribute.GetType() - .GetProperty("TransformNames", BindingFlags.Instance | BindingFlags.Public)!; - var tupleNames = propertyInfo.GetValue(tupleNameAttribute) as IList; + .GetProperty("TransformNames", BindingFlags.Instance | BindingFlags.Public); + var tupleNames = propertyInfo?.GetValue(tupleNameAttribute) as IList; if (tupleNames?.Count > 0) { var args = parameterType.GetGenericArguments();