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

System.ArgumentOutOfRangeException #330

Closed
fvet opened this issue Nov 13, 2023 · 12 comments · Fixed by #336 or #337
Closed

System.ArgumentOutOfRangeException #330

fvet opened this issue Nov 13, 2023 · 12 comments · Fixed by #336 or #337
Labels
bug Something isn't working

Comments

@fvet
Copy link
Contributor

fvet commented Nov 13, 2023

When running v0.1.6, I get following errors when loading a project.

Analyzer 'BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit.CheckBuiltInMethod(OperationAnalysisContext ctx)
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass53_1.<ExecuteOperationAction>b__1() in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 766
   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 1102'
Analyzer 'BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit.CheckBuiltInMethod(OperationAnalysisContext ctx)
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass53_1.<ExecuteOperationAction>b__1() in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 766
   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 1102'
@fvet
Copy link
Contributor Author

fvet commented Nov 13, 2023

Anything I can share to help you troubleshooting?

image

@Arthurvdv
Copy link
Collaborator

There where no changes on this rule, so kinda surprised you have an error on this one.

Do you have a sample AL file which reproduces this error?

@Arthurvdv Arthurvdv added the bug Something isn't working label Nov 13, 2023
@fvet
Copy link
Contributor Author

fvet commented Nov 13, 2023

Unfortunately not (it's a 600+ files app ...)

@Arthurvdv
Copy link
Collaborator

I think I know where the issue occurs. I'll try to see what I can do.

@tscottjendev
Copy link

tscottjendev commented Nov 14, 2023

Having the same issue.

[{
"resource": "/c:/Repos/Jendev/JI-InternalSystem-NEW/Legacy/app.json",
"owner": "generated_diagnostic_collection_name#0",
"code": "AD0001",
"severity": 4,
"message": "Analyzer 'BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')\r\n at System.String.Substring(Int32 startIndex, Int32 length)\r\n at BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit.CheckBuiltInMethod(OperationAnalysisContext ctx)\r\n at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass53_1.b__1() in D:\a\_work\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 766\r\n 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 1102'",
"source": "AL",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 1
}]

@Arthurvdv Arthurvdv linked a pull request Nov 14, 2023 that will close this issue
@Arthurvdv
Copy link
Collaborator

@fvet and @tscottjendev, I've created an fix for this issue and released this in the prerelease.

Could you (briefly) switch over to the prelease version of the LinterCop and provide feedback if this solves your issue?

image
(not sure of you need to run the LC: Download Linter Cop command again to retrieve te latest version)

...or manually download the BusinessCentral.LinterCop.current.dll and rename this to BusinessCentral.LinterCop.dll and copy over the file in C:\Users\<username>\.vscode\extensions\ms-dynamics-smb.al-<version>\bin\Analyzers\

@fvet
Copy link
Contributor Author

fvet commented Nov 14, 2023

@Arthurvdv Running on prerelease version now (using the 'load pre releases' setting + Download Lintercop), but still have similar warnings.

Might be related to the Page.run(0, ...)?

image

(In VSCode, I don't see the warnings, while In DevOps it get the warnings)

image

@fvet
Copy link
Contributor Author

fvet commented Nov 14, 2023

Fixing the Page.Run(0, ...) code (LC0027 warning) makes the app.json "Analyzer 'BusinessCentral.LinterCop.Design.Rule0021BuiltInMethodImplementThroughCodeunit' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'System.ArgumentOutOfRangeException: Index and length must refer to a location within the string." warning dissappear

@tscottjendev
Copy link

The errors have been resolved for me. I have some the LC0029 Page.Run(0, <recordVar>) and no errors. But I don't have any other Page.Run(<pageID>, <recordVar>) warnings (that are not pragma'd out) and since then no errors.

@fvet
Copy link
Contributor Author

fvet commented Nov 14, 2023

@Arthurvdv Just wondering if the LC0027 rule is not too strict about Page.Run(0, <recordVar>). (having pageid set to 0)
Aren't these valid constructs too, as they do not impose a fix page id, resulting in BC internally resolving the page id anyways via the pagemanagement functions?

@Arthurvdv Arthurvdv linked a pull request Nov 14, 2023 that will close this issue
@Arthurvdv
Copy link
Collaborator

I've released a new version v0.30.5 which should resolve this error.

@tscottjendev and @fvet , I've also included the exception for Page.Run(0, <recordVar>) in this release.

Could you provide feedback if the new version resolves this issue?

@Arthurvdv
Copy link
Collaborator

I’m going to assume this issue is resolved.

If you’re still are experiencing problems on this, feel free to re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants