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

Compile with LinterCop after release of AL 13 fails #580

Closed epernst closed 2 months ago

epernst commented 3 months ago

Due to AL Language extension 13, we can no longer debug our AL extension against BC versions older than 20. So get around this issue, we manually have to Uninstall the latest version of the VSCode extension and install an older version. After changing the older version, LinterCop correctly shows warnings and errors in the problem tab.

But if I try to compile the app, then the we get lots of warnings. like: _warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0001FlowFieldsShouldNotBeEditable' threw an exception of type 'System.InvalidOperationException' with message 'System.InvalidOperationException: Nullable object must have a value. at BusinessCentral.LinterCop.Design.Rule0001FlowFieldsShouldNotBeEditable.AnalyzeFlowFieldEditable(SymbolAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass49_2.b__0() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 658 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrowsNoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1102'

But also lots of false errors like: c:\xxx\Source\Features\EnvironmentSetup\EnvironmentFeature.Table.al(1,13): error LC0004: Property "LookupPageID" and "DrilldownPageID" must be filled in table "Environment Feature" because it is used in page "Environment Features" (list) (The page have the properties)

The only option we have found is to disable LinterCop, when compiling. Compilation works fine with LinterCop in our pipelines - where we use the latest version of both the compiler and LinterCop.

Aize-S commented 3 months ago

Same issue here. Using AL Extension v12.6.936426 and LinterCop 0.30.15.0.

warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.EventDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.MethodDeclarationSyntax'. at BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier.AnalyzeInternalProcedures(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b__1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.EventDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.MethodDeclarationSyntax'. at BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier.AnalyzeInternalProcedures(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration' threw an exception of type 'System.NullReferenceException' with message 'System.NullReferenceException: Object reference not set to an instance of an object. at BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration.AnalyzeSemicolonAfterMethodOrTriggerDeclaration(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration' threw an exception of type 'System.NullReferenceException' with message 'System.NullReferenceException: Object reference not set to an instance of an object. at BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration.AnalyzeSemicolonAfterMethodOrTriggerDeclaration(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0052InternalProceduresNotReferencedAnalyzer' 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)'. at BusinessCentral.LinterCop.Design.Rule0052InternalProceduresNotReferencedAnalyzer.MethodSymbolAnalyzer..ctor(CompilationAnalysisContext compilationAnalysisContext) at BusinessCentral.LinterCop.Design.Rule0052InternalProceduresNotReferencedAnalyzer.CheckApplicationObjects(CompilationAnalysisContext compilationAnalysisContext) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass48_1.b0() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 618 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.EventDeclarationSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.MethodDeclarationSyntax'. at BusinessCentral.LinterCop.Design.Rule0025InternalProcedureModifier.AnalyzeInternalProcedures(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' warning AD0001: Analyzer 'BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration' threw an exception of type 'System.NullReferenceException' with message 'System.NullReferenceException: Object reference not set to an instance of an object. at BusinessCentral.LinterCop.Design.Rule0024SemicolonAfterMethodOrTriggerDeclaration.AnalyzeSemicolonAfterMethodOrTriggerDeclaration(SyntaxNodeAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass52_1.b1() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' 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)'. at BusinessCentral.LinterCop.Design.Rule0033AppManifestRuntimeBehind.CheckAppManifestRuntime(CompilationAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>cDisplayClass48_1.b0() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 618 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079' 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.b128_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() [Info - 12:36:59 PM] Connection to server got closed. Server will restart.

Arthurvdv commented 3 months ago

Currently the releases of the LinterCop are only build against the latest version of the AL Language.

I'm looking into to build against multiple AL Languages, where we maybe can resolve this.

image

It's going to be challenging and some rules will are not going to work on previous versions of the AL Languages.

Arthurvdv commented 2 months ago

Working together with @StefanMaron to support multiple version of the AL Language.

image

I've did an overhaul of the build pipeline, to build against multiple version of the AL Language. The next step is to update the VS Code extension to retrieve the matching artifact based on the installed version of the AL Language in VS Code.

Currently we're down to version 12.0 of the AL Language, it this sufficiënt of do we need to go further back? (11, 10, 9, ..)

Aize-S commented 2 months ago

That's great! For us, v12(.7.964847) is enough. We use it to be able to debug against BC14.

epernst commented 2 months ago

Sounds great. V12 is also good enough for us.

But how do we download these? Cannot see these version from the Uninstall->Install Another Version in VSCode. And how about the Powershell script where we now download via https://api.github.com/repos/StefanMaron/BusinessCentral.LinterCop/releases?

Arthurvdv commented 2 months ago

Good news!

image

The combination of the new v0.30.18 version of the LinterCop, combined with the new 0.1.7 version of the VS Code now supports multiple version of the AL Language.

This works automatically on the background, where the VS Code extension grabs the version of the installed AL Language and then retrieves the a matching LinterCop .dll file.

epernst commented 2 months ago

Looks like LinterCop works again in VSCode. Thanks!

But how do we download the correct version for our Pipelines?

Arthurvdv commented 2 months ago

@epernst : In our pipelines we always retrieve the latest AL Language from the marketplace and use that to compile the App.

You can find documentation on this here: https://github.com/StefanMaron/BusinessCentral.LinterCop/blob/master/.assets/DevOps.md

Is this a possible solution?

epernst commented 2 months ago

That's basically the same script we run today. For our pipelines we download the latest AL Language VSIX and then use the script to download LinterCop.

But we keep getting these errors for both for our v14 and v23 builds: warning AL1003: An instance of analyzer BusinessCentral.LinterCop.Design.Rule0001FlowFieldsShouldNotBeEditable cannot be created from C:\bcartifacts.cache\onprem\14.44.49619.0\vsix\extension\bin\Analyzers\BusinessCentral.LinterCop.dll

epernst commented 2 months ago

I'm now down to that it works with your download scripts and my compile scripts, when building a local container.

But it fails when I do the same using ALOps!

Arthurvdv commented 2 months ago

I'm unsure what's wrong in your ADO setup. We're also using ALOps, and works without any issues for us.

I'm getting the idea it's maybe a ADO setup/configration issue (and not an LinterCop issue). Let's continue the conversation on ALOps to figure out what's wrong.

epernst commented 2 months ago

I just created a simpler repo pipeline (without any external scripts or artifacts), but I could not recreate the errors.

Then I ran some of our other failing pipelines again, and it seems that the issue somehow was fixed Friday! We didn't run anything yesterday, as this was a holiday here in Denmark.

I'm not sure if ALops or LinterCop was updated, or what else happened. But not getting any compile errors or warnings, except the ones we expect.