StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
68 stars 27 forks source link

Rule0044AnalyzeTransferFields - Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.PageExtensionSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.TableExtensionSyntax'. #589

Closed pri-kise closed 3 months ago

pri-kise commented 3 months ago

We receive the following warning in our Azure DevOps pipeline.

##[warning]warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.PageExtensionSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.TableExtensionSyntax'.
##[warning]at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.AnalyzeTableExtension(SyntaxNodeAnalysisContext ctx)
##[warning]at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745
##[warning]at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1086'
##[warning]warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0033AppManifestRuntimeBehind' threw an exception of type 'System.MissingMethodException' with message 'System.MissingMethodException: Method not found: 'Microsoft.Dynamics.Nav.CodeAnalysis.Packaging.NavAppManifest Microsoft.Dynamics.Nav.Analyzers.Common.ManifestHelper.GetManifest(Microsoft.Dynamics.Nav.CodeAnalysis.Compilation)'.

We only have on PageExtension in this app, because this is our template app.

pageextension 50000 "PTE CustomerListExt" extends "Customer List"
{
    trigger OnOpenPage();
    begin
        //Message('App published: Hello world');
    end;
}

Versions:

Might be related to #588

pri-kise commented 3 months ago

In another repository we have problems in Azure DevOps Build pipeline with this rule, too.

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.TriggerDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.GlobalVarSectionSyntax'.
   at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.FindGlobalVariables(SyntaxNode node)
   at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.AnalyzeTransferFields(OperationAnalysisContext ctx)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.TriggerDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.GlobalVarSectionSyntax'.
   at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.FindGlobalVariables(SyntaxNode node)
   at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.AnalyzeTransferFields(OperationAnalysisContext ctx)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
Arthurvdv commented 3 months ago

Related to https://github.com/StefanMaron/BusinessCentral.LinterCop/issues/590

pri-kise commented 3 months ago

I've tested it with the Latest AL Language version. Now it's working fine. I will have to update our pipelines now, but at least it's working now.