From 79c59d61895bca1244bf8be5b75c4766e1edc135 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Thu, 23 May 2024 17:51:16 +0200 Subject: [PATCH] Resolve InvalidCastException --- Design/Rule0043SecretText.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Design/Rule0043SecretText.cs b/Design/Rule0043SecretText.cs index 808c0104..0f91765d 100644 --- a/Design/Rule0043SecretText.cs +++ b/Design/Rule0043SecretText.cs @@ -10,7 +10,7 @@ namespace BusinessCentral.LinterCop.Design [DiagnosticAnalyzer] public class Rule0043SecretText : DiagnosticAnalyzer { - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0043SecretText, DiagnosticDescriptors.Rule0000ErrorInRule); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0043SecretText); private static readonly string authorization = "Authorization"; @@ -90,14 +90,7 @@ private void AnalyzeHttpObjects(OperationAnalysisContext ctx) return; } - try - { - if (!IsAuthorizationArgument(operation.Arguments[0])) return; - } - catch (InvalidCastException) - { - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Operation.Syntax.GetLocation(), new Object[] { "Rule0043", "InvalidCastException", "at Line 63" })); - } + if (!IsAuthorizationArgument(operation.Arguments[0])) return; if (!IsArgumentOfTypeSecretText(operation.Arguments[1])) ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0043SecretText, ctx.Operation.Syntax.GetLocation())); @@ -115,6 +108,7 @@ private static bool IsAuthorizationArgument(IArgument argument) case SyntaxKind.LiteralExpression: return SemanticFacts.IsSameName(argument.Value.ConstantValue.Value.ToString(), authorization); case SyntaxKind.IdentifierName: + if (argument.Value.Kind != OperationKind.ConversionExpression) return false; IOperation operand = ((IConversionExpression)argument.Value).Operand; if (operand.GetSymbol().OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Label) return false; ILabelTypeSymbol label = (ILabelTypeSymbol)operand.GetSymbol().OriginalDefinition.GetTypeSymbol();