Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Specified argument was out of the range of valid values. (Parameter 'position')' #7861

Closed
4 of 6 tasks
Arthurvdv opened this issue Sep 28, 2024 · 9 comments
Closed
4 of 6 tasks

Comments

@Arthurvdv
Copy link

1. Describe the bug
I've encounter an ArgumentOutOfRangeException when compiling an extensions with a procedure which has a IntegrationEvent decorator, combined with attaching on the Microsoft.Dynamics.Nav.EditorServices.Host.exe process from another VS Code window.

image

[Error - 9:30:08 AM] 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 X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 698
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceText.LineInfo.GetLineFromPosition(Int32 position) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceText.cs:line 733
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\TextLineCollection.cs:line 65
   at Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SyntaxTree.GetLineSpan(TextSpan span) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Syntax\SyntaxTree.cs:line 201
   at Microsoft.Dynamics.Nav.CodeAnalysis.Text.SourceLocation.GetLineSpan() in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Text\SourceLocation.cs:line 69
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.DiagnosticFormatter.Format(Diagnostic diagnostic, IFormatProvider formatter) in X:\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 X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 245
   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 X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 514
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.RunCore(CompilerTextWriter consoleOutput, ErrorLogger errorLogger, ITelemetryService telemetryService, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 491
   at Microsoft.Dynamics.Nav.CodeAnalysis.CommandLine.CommonCompiler.Run(CompilerTextWriter consoleOutput, ITelemetryService telemetryService, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\CommandLine\CommonCompiler.cs:line 341
   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, String requestVsCodeExtensionVersion) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Utility\ActiveProjectBuilder.cs:line 204
   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 forceBuildOfAllDependencies, CustomTelemetryEvent telemetryEvent, ITelemetryService telemetryService, String vsCodeExtensionVersion) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Utility\ActiveProjectBuilder.cs:line 115
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.LanguageServer.Extensions.CreatePackageRequestHandler.HandleAsync(CreatePackageRequest request, Int32 requestId, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\LanguageServer\Extensions\CreatePackageRequestHandler.cs:line 37
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.MessageProtocol.RequestHandlerBase`1.HandleAsync(JToken requestContents, Int32 requestId, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\MessageProtocol\RequestHandlerBase.cs:line 84
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.RequestRegistry.Process(Message message) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\Endpoints\RequestRegistry.cs:line 84

2. To Reproduce

  1. Create an empty .NET Class Library project
  2. Sample AL project with the MyCodeunit
  3. Add bin/Debug .dll file to al.codeAnalyzers in the settings.json file
  4. Launch and attach to Microsoft.Dynamics.Nav.EditorServices.Host.exe process
codeunit 50100 MyCodeunit
{
    [IntegrationEvent(false, false)]
    local procedure OnAfter()
    begin
    end;
}

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.

3. Expected behavior
While I'm doubting if this is an supported scenario, it would be great if this would be accepted to look into. On development of a custom code analyzer, this makes it a bit more challenging to determine possible errors.

4. Actual behavior
Catching the error to prevent raising an ArgumentOutOfRangeException.

5. Versions:

  • AL Language: v13.1.1065068
  • Visual Studio Code: 1.93.1
  • Business Central: not applicable
  • List of Visual Studio Code extensions that you have installed:
andrzejzwierzchowski.al-code-outline
bartpermentier.al-toolbox
daniel-nt.al-translation-center
eamodio.gitlens
humao.rest-client
ibm.output-colorizer
ms-azuretools.vscode-azurefunctions
ms-azuretools.vscode-azureresourcegroups
ms-dotnettools.csdevkit
ms-dotnettools.csharp
ms-dotnettools.vscode-dotnet-runtime
ms-dotnettools.vscodeintellicode-csharp
ms-dynamics-smb.al
ms-vscode.powershell
nabsolutions.nab-al-tools
nwallace.createguid
postman.postman-for-vscode
rasmus.al-var-helper
redhat.vscode-yaml
rvanbekkum.xliff-sync
shaharkazaz.git-merger
stefanmaron.businesscentral-lintercop
usernamehw.errorlens
vscode-icons-team.vscode-icons
waldo.crs-al-language-extension
wayou.vscode-todo-highlight
wbrakowski.al-navigator
  • Operating System:
    • Windows
    • Linux
    • MacOS

Final Checklist

Please remember to do the following:

  • Search the issue repository to ensure you are reporting a new issue
  • Reproduce the issue after disabling all extensions except the AL Language extension
  • Simplify your code around the issue to better isolate the problem
@BazookaMusic
Copy link
Contributor

Can you try the latest pre-release and verify that it happens there too?

@Arthurvdv
Copy link
Author

I've did some more testing and it seems to be an issue on my workstation 😳

I have the same result on my workstation on the latest pre-release, but also on previous releases, like the 13.0.964488 of the AL Language.

So I've created an VM from scratch, where I try'ed to create a repo, unfortunately without success so far.

I've try'ed

  • The same version of VS Code
  • Same project ( .NET Class Library project) and Sample AL project
  • Install with the same VS Code extensions

Any idea what I can try to possible create a repo on this?

@BazookaMusic
Copy link
Contributor

Maybe you have some hidden characters or something in your original workstation?

@dannoe
Copy link

dannoe commented Oct 1, 2024

Try copying over your vscode user config. Make sure workspace/folder settings are also in sync.
Maybe an extension config is causing this problem.

@Arthurvdv
Copy link
Author

Thank you, @BazookaMusic and @dannoe, for the suggestions!

I'm getting closer but still not fully there. Here's what I've tried so far, although the issue persists:

Steps Taken

  • Removed all VS Code configuration by deleting %APPDATA%\Code\.
  • Removed %USERPROFILE%\.vscode\and reinstalled only the C# and AL Language extensions

However, the error still remains, but I’ve found some new details:

2. To Reproduce

  1. Create an empty .NET Class Library project
  2. Sample AL project with the MyCodeunit
  3. Add bin/Debug .dll file to al.codeAnalyzers in the settings.json file
  4. Launch and attach to Microsoft.Dynamics.Nav.EditorServices.Host.exe process

I discovered step 3 can be skipped, which led me to focus on the "Launch and Attach" part.

When both VS Code windows are open and the AL Language extension is done initializing, attaching from one VS Code instance to the AL project works without any issues.

However, when I try to open the AL project and attach to it almost simultaneously, the error occurs.

Unfortunately, I haven’t been able to reproduce this issue on another workstation, which makes me think there’s still something I’m missing. Any further thoughts on what else to investigate?

@BazookaMusic
Copy link
Contributor

We don't support attaching via the C# debugger on the language server. It's some kind of race condition during the initialization of the project.

The error says that the lines of the file in memory are less than it expected.

Does this occur when you are not using the C# debugger?

@Arthurvdv
Copy link
Author

It's some kind of race condition during the initialization of the project.

I suspect the issue could be related to the timing of the AL Language extension's initialization. When attaching after the extension has fully initialized, the error does not occur.

Does this occur when you are not using the C# debugger?

Yes, the error only occurs when using the C# debugger. Without the debugger, everything functions as expected, and no errors are encountered.

We don't support attaching via the C# debugger on the language server.

I wasn’t aware of that, thank you for the clarification! 😳

I’ll go ahead and close this issue since this is an unsupported scenario. However, I’d love to discuss this further if the opportunity arises, as we rely on the C# debugger for building custom code analyzers.

@BazookaMusic
Copy link
Contributor

@Arthurvdv While the code analyzers that partners have developed are very cool, this is also a scenario that Microsoft does not officially support.

The AL language server is compiled in release mode and we don't provide official tooling to create the code analyzers, eg. publically documented interfaces.

What I would suggest is that you wait until the projects have been loaded before attaching, as that will reduce the chance of something breaking during the initial load.

@Arthurvdv
Copy link
Author

@BazookaMusic Thank you for taking the time to provide feedback, especially considering this isn't officially supported.

When you mentioned attaching the C# debugger to the language server, I thought that in general, it wouldn't work. However, waiting until the project is fully loaded before attaching is a feasible workaround to prevent this error from happening.

code analyzers that partners have developed are very cool

Thank you! ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants