From f70f6ceb15e326c99e4cf38340c31b3194b32017 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Fri, 5 Apr 2024 21:43:43 +0200 Subject: [PATCH] FailFast on GetOperation exception --- .../Performance/CSharpUseSearchValues.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Performance/CSharpUseSearchValues.cs b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Performance/CSharpUseSearchValues.cs index 5a39ce4b80..1991f7bea9 100644 --- a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Performance/CSharpUseSearchValues.cs +++ b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Performance/CSharpUseSearchValues.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -114,8 +115,19 @@ internal static bool IsConstantByteOrCharArrayCreationExpression(SemanticModel s } else { + IOperation? operation; + try + { + operation = semanticModel.GetOperation(expression); + } + catch (Exception ex) + { + Environment.FailFast(ex.Message, ex); + throw; + } + return - semanticModel.GetOperation(expression) is { } operation && + operation is not null && IsConstantByteOrCharCollectionExpression(operation, values, out length); }