microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
750 stars 247 forks source link

'textDocument/inlayHint' failed with error: 'Object reference not set to an instance of an object.' #7794

Open JavierFuentes opened 4 months ago

JavierFuentes commented 4 months ago

1. Describe the bug the setting "editor.inlayHints.enabled": "on" throws error:

2. To Reproduce activate this setting "editor.inlayHints.enabled": "on" in VSCode for a BC extension:

3. Expected behavior no errors

4. Actual behavior

[Error - 10:08:49] Please report this issue to https://github.com/microsoft/al/issues including information on how to reproduce it, if possible.
Processing of message 'textDocument/inlayHint' failed with error: 'Object reference not set to an instance of an object.'
Details:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Dynamics.Nav.CodeAnalysis.SymbolDisplayVisitor.GetRecordStructure(Symbol symbol) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\SymbolDisplay\SymbolDisplayVisitor.cs:line 1485
   at Microsoft.Dynamics.Nav.CodeAnalysis.SymbolDisplayVisitor.VisitParameter(ParameterSymbol symbol) in X:\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\SymbolDisplay\SymbolDisplayVisitor.cs:line 273
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.LanguageServer.InlayHintRequestHandler.CreateContent(ISymbol symbol, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\LanguageServer\InlayHintRequestHandler.cs:line 115
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.LanguageServer.InlayHintRequestHandler.GetInlayHints(Document document, Nullable`1 range, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\LanguageServer\InlayHintRequestHandler.cs:line 81
   at Microsoft.Dynamics.Nav.EditorServices.Protocol.LanguageServer.InlayHintRequestHandler.HandleAsync(InlayHintRequest request, Int32 requestId, CancellationToken cancellationToken) in X:\Prod\Microsoft.Dynamics.Nav.EditorServices.Protocol\LanguageServer\InlayHintRequestHandler.cs:line 46
   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

5. Versions:

Final Checklist

Please remember to do the following:

Internal work item: AB#542456

azure-boards[bot] commented 4 months ago

✅ Successfully linked to Azure Boards work item(s):

kalberes commented 4 months ago

IT would be quite helpful for a fix a small repro.

joandrsn commented 3 months ago

I dont have an example, but I have noticed a place where the error occurs.

We have an app A which exposes this function:

procedure GetWorkTypeRelationByResourceNo(ResourceNo: Code[20]; WorkType: Code[20]; var WorkTypeRealtion: Record "Work Type Relation3_LON")
begin
end;

When this function is called in our customers extension B, the inline hits are missing and the error is produced. To create a lot of these errors I can simply press Ctrl+Alt (Normal to show Inline Hits). If I comment out the line with Functionpublisher, the error isn't produced. Maybe it's because we have a number in our tablename?

local procedure CreatePayrollJnlEntry(ResLedgerEntry: Record "Res. Ledger Entry") Result: Integer
var
    Employee: Record Employee_LON;
    WorkTypeRelation: Record "Work Type Relation3_LON";
    Functionpublisher: Codeunit Functionpublisher_LON;
begin
    Employee.SetRange("Resource No.", ResLedgerEntry."Resource No.");
    if not Employee.FindFirst() then
        exit;
    Functionpublisher.GetWorkTypeRelationByResourceNo(ResLedgerEntry."Resource No.", ResLedgerEntry."Work Type Code", WorkTypeRelation);
    if CreateAbsenceJnlLine(ResLedgerEntry, WorkTypeRelation, Employee) then
        Result += 1;
    if CreatePayrollJnlLine(ResLedgerEntry, WorkTypeRelation, Employee) then
        Result += 1;
end;

I have tried to downgrade to 13.0.1027618, but the problem persists (Currently I'm using 13.1.1065068)

SKnoppers commented 3 months ago

I encounter the same error as described above. (13.1.1065068)

When switching to the file in vscode the error is thrown once. Every time i add a new line and wait for the inline hint it throws the error again.

Example:

namespace DefaultPublisher.RepScenario;
using Microsoft.Inventory.Tracking;

codeunit 50100 "Rep. Scenario"
{
    trigger OnRun()
    var
        TrackingSpecification: Record "Tracking Specification";
        ReservMgt: Codeunit "Reservation Management";
    begin
        ReservMgt.CreateReservation('', WorkDate(), 1, 1, TrackingSpecification);
        // Add new line below and wait.
    end;
}