Al: Rule137DoNotDeclareVariablesThatAreUnused Argument null Exception

Created on 3 Apr 2019  Â·  9Comments  Â·  Source: microsoft/AL

Describe the bug
My Settings:

"al.enableCodeAnalysis": true,
    "al.codeAnalyzers": [
        "${CodeCop}"
    ],
Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused' threw an exception of type 'System.ArgumentNullException' with message 'System.ArgumentNullException: Il valore non può essere null.
Nome parametro: syntax
   in Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.CheckSyntaxNode(SyntaxNode syntax) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:riga 1462
   in Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:riga 547
   in Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused.UnusedVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule137DoNotDeclareVariablesThatAreUnused.cs:riga 172
   in Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:riga 745
   in Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:riga 1082'

Versions:

  • AL Langauge: 3.0.115791
  • Business Central: 14.029530 IT Localization Cronus DB
bug ships-in-future-update

All 9 comments

Hi @stefanoPrimo, thanks for filing this issue. Can you please try and figure out what part of your code generates this exception? Without a code snippet to analyze, we can't figure out how to trigger the exception you are experiencing.

Hi @JohanStenberg100, thanks for the quick response.
Honestly, I don't really know where is the code that throws that error because in the extension there are like 121 Files (with al extension) and this error is pointing to the app.json file (that I don't think that is here the problem). Is there some file that I could debug to find out where is the problem?

I've found where is the problem: all it is due to the variable dataType "Dialog".
Given that I removed all Dialog variables to a codeunit and the code cop turned back alive!

@stefanoPrimo thanks for figuring it out. Can you provide me with a small sample AL file which reproduces this error? Simply using a Dialog variable doesn't cut it. Thanks

Hi,
I've recreated the error, here you are:
ALProject6.zip

Hi again @stefanoPrimo, I can now reproduce this locally, thanks!

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 31126 and VS Code Extension Version 3.0.117557.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read:
https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/
https://blogs.msdn.microsoft.com/freddyk/2018/04/16/which-docker-image-is-the-right-for-you/

@JohanStenberg100

Working with AL build 3.0.126610 still shows me the 'Rule137DoNotDeclareVariablesThatAreUnused' multiple times. Project is however too large to pinpoint the source ...

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused' threw an exception of type 'System.ArgumentNullException' with message 'System.ArgumentNullException: Value cannot be null.
Parameter name: syntax
   at Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.CheckSyntaxNode(SyntaxNode syntax) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:line 1462
   at Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:line 547
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused.UnusedVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule137DoNotDeclareVariablesThatAreUnused.cs:line 172
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in F:\a\435\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 F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1082'

Hi @fvet, I have backported this to the 3.0.X release yesterday. It will be available in the next update. Remember, fixes here target the latest preview, but this issue in particular has been backported.

Was this page helpful?
0 / 5 - 0 ratings