BusinessCentral.LinterCop icon indicating copy to clipboard operation
BusinessCentral.LinterCop copied to clipboard

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')

Open epernst opened this issue 2 years ago • 11 comments

Since the LinterCop update yesterday our App Pipeline fails during compilation with: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')

The "funny" thing is that it does not fail in our local sandboxes, only when running the ADO pipeline. When disabling LinterCop, then it works without any issues.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position') at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceText.LineInfo.IndexOf(Int32 position) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 698 at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceText.LineInfo.GetLineFromPosition(Int32 position) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 733 at Microsoft.Dynamics.Nav.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\TextLineCollection.cs:line 66 at Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SyntaxTree.GetLineSpan(TextSpan span) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Syntax\SyntaxTree.cs:line 201 at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceLocation.GetLineSpan() in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceLocation.cs:line 66 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.DiagnosticFormatter.Format(Diagnostic diagnostic, IFormatProvider formatter) in D:\a_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Diagnostics\DiagnosticFormatter.cs:line 38 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.ReportErrors(IEnumerable1 diagnostics, CompilerTextWriter consoleOutput, ErrorLogger errorLogger, CompilationOptions options) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 245 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.PackageTheModule(Compilation compilation, CompilerTextWriter consoleOutput, CancellationToken cancellationToken, ErrorLogger errorLogger, AnalyzerDriver analyzerDriver, Predicate1 filterOpt, Predicate1 radCompilationFilter) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 741 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.RunCoreImpl(CompilerTextWriter consoleOutput, ErrorLogger errorLogger, Compilation compilation, AnalyzerDriver analyzerDriver, IEnumerable1 analyzerExceptionDiagnostics, IEnumerable1 additionalTextFiles, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 551 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.RunCore(CompilerTextWriter consoleOutput, ErrorLogger errorLogger, ITelemetryService telemetryService, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 482 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.Run(CompilerTextWriter consoleOutput, ITelemetryService telemetryService, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 336 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.Alc.<>c__DisplayClass1_0.<Run>b__0(CompilerTextWriter textWriterOut, CompilerTextWriter _) in D:\a\_work\1\s\source\Prod\alc\Alc.cs:line 37 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.ConsoleUtil.RunWithOutput[T](Boolean useUtf8Encoding, Func3 func) in D:\a_work\1\s\source\Prod\alc\ConsoleUtil.cs:line 25 at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.Alc.Run(String clientDirectory, String baseDirectory, String[] args, IAnalyzerAssemblyLoader analyzerLoader) in D:\a_work\1\s\source\Prod\alc\Alc.cs:line 37 App generation failed with exit code -1

BC version 14.29 AL Compiler version 10.1.10.52128

epernst avatar Nov 15 '22 08:11 epernst

Actually, it was enough to disable LC0022.

epernst avatar Nov 15 '22 09:11 epernst

Actually, it was enough to disable LC0022 and LC0023.

@epernst Thanks for this comment. This did solve my issue in my project, too.

If this issue is really caused by the BusinessCentralLinterCop, then I probably can close the following issue. https://github.com/microsoft/AL/issues/7241

pri-kise avatar Nov 15 '22 09:11 pri-kise

@epernst do you use the latest vsix from the marketplace in your pipelines?

If yes, would you be up for a quick teams call for me to have look why this fails? Its a bit hard for me to reproduce this.

StefanMaron avatar Nov 15 '22 09:11 StefanMaron

I have the same problem on my VS Code compile step. ( see related issue)

pri-kise avatar Nov 15 '22 10:11 pri-kise

I have added a try catch for this. It should trow a Rule0000 now instead of that error, this way you should be able to identify the code that leads to this, and send an example how to reproduce. Then I can fix this

StefanMaron avatar Nov 15 '22 11:11 StefanMaron

We always use the latest versions, both of the AL compiler and LinterCop. It's harder to reproduce it, as we're not getting the errors when building it locally. And it's only for one of our App Pipelines, the other works fine.

epernst avatar Nov 15 '22 11:11 epernst

@StefanMaron have you planned to add a try catch for rule LC0023, too? This is the rule that leads to the compile error on my side. After disable this rule in the ruleset.json everything is working again.

pri-kise avatar Nov 15 '22 12:11 pri-kise

Oh I can do that, is it also the ArgumentOutOfRangeException ? I do not want to create a catch all block but create them individually

StefanMaron avatar Nov 15 '22 13:11 StefanMaron

Yes both lc0022 and lc0023 gives the error, even if it succeded with only LC0022 disabled when I first ran it.

epernst avatar Nov 15 '22 13:11 epernst

Yes LC0023 leads to the error in the mentioned issue: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position') (After disabling this specific rule, the error disappears)

pri-kise avatar Nov 15 '22 14:11 pri-kise

Oh I did not change anything since the try catch yesterday

StefanMaron avatar Nov 16 '22 14:11 StefanMaron

@StefanMaron would be very helpful if you find some time to add a try catch for the rule LC0023, too. Right now, we have to disable the rule LC0023 for every app, to be able to compile the apps.

pri-kise avatar Dec 15 '22 06:12 pri-kise

@StefanMaron would be very helpful if you find some time to add a try catch for the rule LC0023, too. Right now, we have to disable the rule LC0023 for every app, to be able to compile the apps.

Thanks for the reminder! Just pushed a new version, please give it a try and let me know

StefanMaron avatar Dec 16 '22 05:12 StefanMaron

@StefanMaron it doesn't seem to fixed

[Error - 08:39:23] Please report this issue to https://github.com/microsoft/al/issues including information on how to reproduce it, if possible.
Processing of message 'al/createPackage' failed with error: 'Specified argument was out of the range of valid values. (Parameter 'position')'
Details:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceText.LineInfo.IndexOf(Int32 position) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 698
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceText.LineInfo.GetLineFromPosition(Int32 position) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 733
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\TextLineCollection.cs:line 65
   at Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SyntaxTree.GetLinePosition(Int32 position) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Syntax\SyntaxTree.cs:line 203
   at Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SyntaxTree.GetLineSpan(TextSpan span) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Syntax\SyntaxTree.cs:line 201
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceLocation.GetLineSpan() in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceLocation.cs:line 69
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.DiagnosticFormatter.Format(Diagnostic diagnostic, IFormatProvider formatter) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Diagnostics\DiagnosticFormatter.cs:line 38
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.ReportErrors(IEnumerable`1 diagnostics, CompilerTextWriter consoleOutput, ErrorLogger errorLogger, CompilationOptions options) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 245
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.PackageTheModule(Compilation compilation, CompilerTextWriter consoleOutput, CancellationToken cancellationToken, ErrorLogger errorLogger, AnalyzerDriver analyzerDriver, Predicate`1 filterOpt, Predicate`1 radCompilationFilter) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 741
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.RunCoreImpl(CompilerTextWriter consoleOutput, ErrorLogger errorLogger, Compilation compilation, AnalyzerDriver analyzerDriver, IEnumerable`1 analyzerExceptionDiagnostics, IEnumerable`1 additionalTextFiles, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 551
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.RunCore(CompilerTextWriter consoleOutput, ErrorLogger errorLogger, ITelemetryService telemetryService, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 482
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.Run(CompilerTextWriter consoleOutput, ITelemetryService telemetryService, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 336
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.Utility.ActiveProjectBuilder.Build(VsCodeWorkspace workspace, Project builtProject, StreamingTextWriter outputWriter, Boolean isRad, IList`1 args, CancellationToken cancellationToken, IResponseQueue responseQueue, ITelemetryService telemetryService, Boolean forceBuild, IList`1 outputFiles, CustomTelemetryEvent telemetryEvent) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Utility\ActiveProjectBuilder.cs:line 180
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.Utility.ActiveProjectBuilder.BuildWorkspaceAsync(CancellationToken cancellationToken, IFileSystem fileSystem, VsCodeWorkspace workspace, String projectDir, IList`1 args, Boolean buildDependencyPackage, Boolean isRad, IResponseQueue responseQueue, Boolean forceBuildOfAllDependecnies, CustomTelemetryEvent telemetryEvent, ITelemetryService telemetryService) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Utility\ActiveProjectBuilder.cs:line 105
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.LanguageServer.Extensions.CreatePackageRequestHandler.HandleAsync(CreatePackageRequest request, Int32 requestId, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\LanguageServer\Extensions\CreatePackageRequestHandler.cs:line 38
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.MessageProtocol.RequestHandlerBase`1.HandleAsync(JToken requestContents, Int32 requestId, CancellationToken cancellationToken) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\MessageProtocol\RequestHandlerBase.cs:line 103
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.RequestRegistry.Process(Message message) in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Endpoints\RequestRegistry.cs:line 108

I made sure, that I have the latest LinterCop Version installed. image

I closed all vs code windows, but the error is still present

pri-kise avatar Dec 16 '22 07:12 pri-kise

@StefanMaron it somehow looks like the bug isn't fixed totally for rule 23. I recieve the info for the rule 23 in the output, but the compiler crashes if the rule 23 is enabled.

pri-kise avatar Jan 23 '23 07:01 pri-kise

@StefanMaron Unfortunately, the error hasn't been fixed yet. Various colleagues have the problem every now and then, some do not. We havn't yet been able to determine the reason. Suppressing the rule LC0023 in every app (even though it have already been set to "None" in our RuleSet) only works until you want to apply the rule. A solution would be very welcome! Thank you.

GOB-Andrea avatar Feb 09 '23 15:02 GOB-Andrea

@epernst, @pri-kise, @GOB-Andrea, are you still experiencing issues with the LC0023 rule? If so, can you share a small code example for me to investigate on this? Or has the issue been resolved in the meantime and can I close this issue?

Arthurvdv avatar Nov 07 '23 18:11 Arthurvdv

I will reenable this rule on my projects and test if I still have this problem.

pri-kise avatar Nov 08 '23 07:11 pri-kise

I reenabled this rule on some projects with the preview version for the AL Lanuage Extension and everthing seems to be fine now.

pri-kise avatar Nov 08 '23 14:11 pri-kise

Thank you for testing this and providing feedback!

If this issue would reoccur it would be best to create a new issue including a sample code sample which produces this error.

Arthurvdv avatar Nov 08 '23 15:11 Arthurvdv