Closed JuricaB closed 5 years ago
Jup, very annoying
Hi @JuricaB and @BartPermentier, thank you for reporting this issue. Can you copy-paste here the stack trace that you are getting when using the analyzer?
The screenshot above is cropped and doesn't show us exactly what the InvalidCastException is and where it happens.
Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Symbols.SourceParameterSymbol' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.IVariableSymbol'.
at Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex.AnalyzeInvocations(SyntaxNodeAnalysisContext syntaxNodeAnalysisContex, ImmutableDictionary2 processInvocations) in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule210SuboptimalIndex.cs:line 86 at Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex.<>c.<Analyze>b__5_0(SyntaxNodeAnalysisContext syntaxNodeAnalysisContex) in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule210SuboptimalIndex.cs:line 66 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 742 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable
1 info) in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079'
@BartPermentier can you please provide a snippet of code that reproduces the issue?
Hi @atoader,
Please see below for the snippet I can use to replicate this:
codeunit 50100 "TestError"
{
procedure Test210(var GLEntry: Record "G/L Entry");
var
GLReg: Record "G/L Register";
begin
GLEntry.FindFirst();
GLReg.SetRange("From Entry No.", 0, GLEntry."Entry No.");
if GLReg.IsEmpty() then;
end;
}
In addition, the project needs to have settings.json file with CodeCop enabled.
Thanks,
Jurica
As a side note, I can't see how to copy full stack trace of error from VS Code Problems pane - is there a trick to it?
That might be a limitation of VS Code, but you should be able to find the exception in the EditorServices.log file in the .vscode/extensions/microsoft.al-*/bin
Sorry @atoader - I looked under .vscode\extensions\ms-dynamics-smb.al-4.0.182565\bin\EditorServices.log and there is nothing of importance logged in that file.
Can you set the: to Verbose, restart your editor, reproduce the issue, and inspect the file.
After you are done, do not forget to change it back to Normal.
Thanks @atoader after settig to Verbose I can copy the message:
Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Symbols.SourceParameterSymbol' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.IVariableSymbol'. at Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex.AnalyzeInvocations(SyntaxNodeAnalysisContext syntaxNodeAnalysisContex, ImmutableDictionary
2 processInvocations) in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule210SuboptimalIndex.cs:line 86
at Microsoft.Dynamics.Nav.CodeCop.Design.Rule210SuboptimalIndex.<>c.1 info) in F:\a\586\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1079'
I think this is related to some characters in the app.json that the AL Language extension does not like.
Auto format the app.json with AL Language does not help, but if you instead use the VSCode function "Format Document with..." and select "JSON Language Features". I've had issues with "hard spaces" (char 160) and a trailing new line. After I've reformatted my app.json, the error disappears.
The hard spaces also caused issues when publishing...
@jwikman
The fact that these errors disappear when you save the app.json file is an artefact of the poor caching of the errors generated by the background processes (Like the fact that the errors disappear when you click on one). Random unexpected errors are thrown against the app.json
file not the file that triggered them. Saving any change to the app.json
file deletes all errors attached to it and causes a regeneration of the errors that are supposed to be attached to just that file. These errors are not "supposed" to be attached so they don't come back until a full regeneration is triggered. Restarting vscode does this as does toggling "al.enableCodeAnalysis":
in settings.json
NB: There is another error triggered by comments in app.json
for a couple of versions of the extension, but that's not this.
@jwikman : @rdebath is right - it is not related to app.json characters issue (I have seen that one before too). Using Format Document With...JSON appears to fix the issue- but so does making any change in app.json and saving it. After reopening the project, same error shows up again.
@JuricaB @rdebath, you are right guys. The error is back now. :(
Hi @JuricaB, I am trying to reproduce on 4.0.182565 using the steps above. I am using the code from your snippet (with the swapped SetRange and FindFirst lines) to provoke the AA0210 warning, but still can not get repro. The problem might happen for some specific app.json items. Could you share your app.json. Could you also try to repro the bug with the latest AL extension daily build, it might be already fixed there as we recently fixed similar issue. Thank you.
Hi @AndreyKorepanov
See below for app.json:
{
"id": "fb4a6873-0ac6-4345-9f3c-767576998a3c",
"name": "WAVE2",
"publisher": "Default publisher",
"version": "1.0.0.0",
"brief": "",
"description": "",
"privacyStatement": "",
"EULA": "",
"help": "",
"url": "",
"logo": "",
"dependencies": [
{
"appId": "63ca2fa4-4f03-4f2b-a480-172fef340d3f",
"publisher": "Microsoft",
"name": "System Application",
"version": "1.0.0.0"
},
{
"appId": "437dbf0e-84ff-417a-965d-ed2bb9650972",
"publisher": "Microsoft",
"name": "Base Application",
"version": "15.0.0.0"
}
],
"screenshots": [],
"platform": "15.0.0.0",
"idRanges": [
{
"from": 50100,
"to": 50149
}
],
"contextSensitiveHelpUrl": "https://WAVE2.com/help/",
"showMyCode": false,
"runtime": "4.0",
"features": ["TranslationFile"]
}
You also need to have settings.json with CodeCop enabled:
{
"al.enableCodeAnalysis": true,
"al.codeAnalyzers": [
"${CodeCop}"
]
}
Note also I am still replicating this on 4.0.182565 - I will try daily build later today and let you know.
@JuricaB, closing this issue as it has been fixed in our latest preview builds from master (version 5.0.0 and above) and for 15.x (from version 4.0.186154 and above). The fix will also be available in the next update of the AL extension in the marketplace. If you can still reproduce this issue on our latest developer preview, please open a new issue and reference this one.
I can reproduce this in the latest preview; but that's over two weeks old.
When is the bcsandbox-master
going to be starting up again then?
Should this be @freddydk ?
@rdebath, which is the version of the AL extension that you are getting from the container?
In the Run directory: al-4.0.176004.vsix In the 150/AL Dev: Identity Language="en-US" Id="al" Version="4.0.176004" Microsoft.Dynamics.Nav.Server.exe version: 15.0.36510 Docker images version: 15.0.36560
@rdebath we have pushed out a new VSIX update to the marketplace. Does it still reproduce on that version? Could you provide a sample to reproduce the issue?
I no longer see this error.
Describe the bug When opening a project I previously closed while app.json was open, AL language causes error as below. It also happens if app.json was among last active files, but not currently active.
To Reproduce Steps and to reproduce the behavior:
Notes:
If file other than app.json is active, then actual message for AA0210 is shown together with error. If App.json is only active file, then just the error is shown.
Making any change to app.json and saving it clears the error until next session, but it also hides AA0210 message until you open another object.
AL Code to reproduce the issue
Expected behavior Not to get the error. Editing app.json should not affect the problems pane in this way.
Screenshots If applicable, add screenshots to help explain your problem.
5. Versions: