StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
74 stars 31 forks source link

[Preview] - LC0043 Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.BoundLocal' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.IConversionExpression'. (v14.0.1010940 (pre-release)) #622

Closed pri-kise closed 4 months ago

pri-kise commented 4 months ago

I receive the following warning in my project:

Analyzer 'BusinessCentral.LinterCop.Design.Rule0043SecretText' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.BoundLocal' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.IConversionExpression'. at BusinessCentral.LinterCop.Design.Rule0043SecretText.IsAuthorizationArgument(IArgument argument) at BusinessCentral.LinterCop.Design.Rule0043SecretText.AnalyzeHttpObjects(OperationAnalysisContext ctx) at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass54_1.b__1() in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 773 at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1088'

AL Language Version: v14.0.1010940 (pre-release)

Arthurvdv commented 4 months ago

@pri-kise , I've added an LC0000 rule so we can investigate where this exception occurs.

Could you try with the Pre-Release version of the LinterCop and share a small code sniplet on this?

pri-kise commented 4 months ago

I receive the info here:

var
        RestClient: Codeunit "Rest Client"; //global variable
    local procedure PrepareRestClient(GraphOptionalParameters: Codeunit "PTE Graph Opt. Parameters")
    var
        RequestHeaders: Dictionary of [Text, Text];
        RequestHeaderName: Text;
    begin
        RequestHeaders := GraphOptionalParameters.GetRequestHeaders();
        foreach RequestHeaderName in RequestHeaders.Keys() do
            RestClient.SetDefaultRequestHeader(RequestHeaderName, RequestHeaders.Get(RequestHeaderName)); //In this line
    end;
Arthurvdv commented 4 months ago

Thank you for providing the code sample.

This should now be resolved in the (pre)release version of v0.30.20 of the LinterCop.

pri-kise commented 4 months ago

Fixed in preview version

Arthurvdv commented 4 months ago

Version v0.30.20 of the LinterCop is now released.