From c8c1659f7ebe881e9e838641501b7cc8b331c749 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Thu, 15 Feb 2024 17:42:42 +0100 Subject: [PATCH] Add Try/Catch to investigate InvalidCastException issue --- Design/Rule0032ClearCodeunitSingleInstance.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Design/Rule0032ClearCodeunitSingleInstance.cs b/Design/Rule0032ClearCodeunitSingleInstance.cs index 9733ba0b..794dd2d6 100644 --- a/Design/Rule0032ClearCodeunitSingleInstance.cs +++ b/Design/Rule0032ClearCodeunitSingleInstance.cs @@ -8,7 +8,7 @@ namespace BusinessCentral.LinterCop.Design [DiagnosticAnalyzer] public class Rule0032ClearCodeunitSingleInstance : DiagnosticAnalyzer { - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance, DiagnosticDescriptors.Rule0000ErrorInRule); public override void Initialize(AnalysisContext context) { @@ -30,8 +30,15 @@ private void ClearCodeunit(OperationAnalysisContext ctx) IOperation operand = ((IConversionExpression)operation.Arguments[0].Value).Operand; if (operand.GetSymbol().GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Codeunit) return; - if (IsSingleInstanceCodeunitWithGlobalVars((ICodeunitTypeSymbol)operand.GetSymbol().GetTypeSymbol())) - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance, ctx.Operation.Syntax.GetLocation(), new Object[] { operand.GetSymbol().Name, operand.GetSymbol().GetTypeSymbol().Name })); + try // temporary add an Try/Catch to investigate issue https://github.com/StefanMaron/BusinessCentral.LinterCop/issues/523 + { + if (IsSingleInstanceCodeunitWithGlobalVars((ICodeunitTypeSymbol)operand.GetSymbol().GetTypeSymbol())) + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance, ctx.Operation.Syntax.GetLocation(), new Object[] { operand.GetSymbol().Name, operand.GetSymbol().GetTypeSymbol().Name })); + } + catch + { + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0000ErrorInRule, ctx.Operation.Syntax.GetLocation(), new Object[] { "Rule0032", "Exception", "at Line 35" })); + } } private void ClearAllCodeunit(OperationAnalysisContext ctx)