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
744 stars 245 forks source link

the debugger does not work, does not stop on breakpoints #6327

Closed apaGitHub closed 3 years ago

apaGitHub commented 3 years ago

Describe the bug The app is published and works as expected (Payment Method Code for 8 Sales Orders for Adatum Corporation – and any other I try - are changed when the Customer Card Payment Method Code is changed), with below launch.json, app.json, and codeunit used to test the debugger.

The debugger does not stop at breakpoints, or otherwise seem to work.

The only result I have seen in the debugger is that the CALL STACK will sometimes show “RUNNING.”

To Reproduce Steps and to reproduce the behavior: Aside from the below files, have also tried to use in settings.json: "al.editorServicesLogLevel": "Debug". (restarted VS Code to take effect) And then "al.editorServicesLogLevel": "Verbose" (restarted VS Code to take effect)

EditorServices.log, and the debugger (DebuggerServices.log) are NOT output to the C:\Users\.vscode\extensions... \bin directory.

The only new directory created in the path is 365businessdevelopment.bdev-al-xml-doc-1.0.2, which is empty. There is this “Unknown Config Setting” added setting to settings.json: bdev-al-xml-doc.checkProcedureDocumentation": true, (tried true and false without causing an effect).

Cleared browser cache. Cleared .alchache in VS Code.

In total, no effect to get the debugger to pause on breakpoints.

AL Code to reproduce the issue launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Microsoft cloud sandbox",
            "request": "launch",
            "type": "al",
            "environmentType": "Sandbox",
            "environmentName": "XYZ -SANDBOX",
            "startupObjectId": 22,
            "startupObjectType": "Page",
            "breakOnError": true,
            "launchBrowser": true,
            "enableLongRunningSqlStatements": true,
            "enableSqlInformationDebugger": true
        }
    ]
}

in launch.json had also tried: "breakOnRecordWrite": true (no effect)

app.json

{
  "id": "XYZ ID”
  "name": "XYZ Name",
  "publisher": "XYZ Publisher",
  "version": "1.0.0.0",
  "brief": "",
  "description": "",
  "privacyStatement": "",
  "EULA": "",
  "help": "",
  "url": "",
  "logo": "",
  "dependencies": [],
  "screenshots": [],
  "platform": "17.0.0.0",
  "application": "17.0.0.0",
  "idRanges": [
    {
      "from": 60000,
      "to": 60049
    }
  ],
  "contextSensitiveHelpUrl": "XYZ URL”
  "showMyCode": true,
  "runtime": "6.0"
}

codeunit

codeunit 60002 XYZEvents
{
    trigger OnRun()
    begin

    end;

    [EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterValidateEvent', 'Payment Method Code', true, true)]
    local procedure XYZ_Customer_MethodPaymentCode_OnAfterValidate(var Rec: Record Customer)
    var
        SalesHeader: Record "Sales Header";
    begin
        **SalesHeader.SetRange("Sell-to Customer No.", Rec."No."); // breakpoint set here and every other line of code without effect**
        if SalesHeader.FindSet(true, false) then
            repeat
                SalesHeader.Validate("Payment Method Code", Rec."Payment Method Code");
                SalesHeader.Modify(true);
            until SalesHeader.Next() = 0;
    end;

    var
        myInt: Integer;
}

In the above codeunit, also went to Go to definition for “Sales Header” Opened: table 36 "Sales Header", set breakpoint on InitInsert, with no effect.

trigger OnInsert()
    var
        O365SalesInvoiceMgmt: Codeunit "O365 Sales Invoice Mgmt";
        StandardCodesMgt: Codeunit "Standard Codes Mgt.";
    begin
        InitInsert;
        InsertMode := true;

        SetSellToCustomerFromFilter;

        if GetFilterContNo <> '' then
            Validate("Sell-to Contact No.", GetFilterContNo);

        Validate("Payment Instructions Id", O365SalesInvoiceMgmt.GetDefaultPaymentInstructionsId);

        if "Salesperson Code" = '' then
            SetDefaultSalesperson;

        if "Sell-to Customer No." <> '' then
            StandardCodesMgt.CheckCreateSalesRecurringLines(Rec);

        // Remove view filters so that the cards does not show filtered view notification
        SetView('');
    end;

Expected behavior VS Code should stop on breakpoints and show elements in debugger side panel.

Screenshots If applicable, add screenshots to help explain your problem. debug1

5. Versions:

VS Code: Version: 1.51.1 AL Language: v6.1.362735

In BC Sandbox, using CRONUS USA, Inc.: Application Version: 17.0.16993.0 Platform Version: 17.0

kalberes commented 3 years ago
  1. I assume that you have a sandbox named XYZ -SANDBOX?
  2. I assume that you have started debugging with F5?
  3. If you trigger a message box from the event that is visible when you run the application? Testing that your event subscription is really called.
  4. Search also in the bin subdirectories too for the debuggerservices.log file. It should be there, else you are not debugging with the Debug Adapter for the AL language extension.
apaGitHub commented 3 years ago

Thanks for the reply.

1. I assume that you have a sandbox named XYZ -SANDBOX?

2. I assume that you have started debugging with F5?

3. If you trigger a message box from the event that is visible when you run the application? Testing that your event subscription is really called.

4. Search also in the bin subdirectories too for the debuggerservices.log file. It should be there, else you are not debugging with the Debug Adapter for the AL language extension.

Your assumptions are correct:

  1. I assume that you have a sandbox named XYZ -SANDBOX? YES
  2. I assume that you have started debugging with F5? YES
  3. If you trigger a message box from the event that is visible when you run the application? Testing that your event subscription is really called.

Yes, the subscription is really called, but to show via triggering a message box, I have refactored the codeunit (below) and then provided the screenshots of the messages. The changes occur as expected.

  1. 365businessdevelopment.bdev-al-xml-doc-1.0.2 was created yesterday when I added "al.editorServicesLogLevel": "Debug" But then changed it to: "al.editorServicesLogLevel": "Verbose" Changing it back to "al.editorServicesLogLevel": "Debug"has not had an effect and the folder is empty, no bin subdirectories. This folder seems to be associated with the "AL XML Documentation," I have a newer version with subfolders created at a previous time yesterday (see image below settings.json) but the but the bin folder seems to have only files associated with ALCodeCommentMarkdownCreator.

Does it then seem that I am "not debugging with the Debug Adapter for the AL language extension"?

How to determine if I am not debugging with the Debug Adapter for the AL language extension? Attached also is my settings.json file (below).

[EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterValidateEvent', 'Payment Method Code', true, true)]
    local procedure XYZ_Customer_MethodPaymentCode_OnAfterValidate(var Rec: Record Customer)
    var
        SalesHeader: Record "Sales Header";
    begin
        SalesHeader.SetRange("Sell-to Customer No.", Rec."No.");
        Message('Change made to the Customer Card Payment Method Code');
        Count := 0;
        if SalesHeader.FIND('-') then  
            repeat  
                Count := Count + 1;  
            until SalesHeader.NEXT = 0;  
            MESSAGE(Text000 + '%1', Count);
        Count := 0;  
        if SalesHeader.FindSet(true, false) then
            repeat
                Count := Count + 1;
                MESSAGE(Text001 + Text002 + '%1', Count);
                SalesHeader.Validate("Payment Method Code", Rec."Payment Method Code");
                SalesHeader.Modify(true);
            until SalesHeader.Next() = 0;
    end;

    var
        Count: Integer;
        Text000: Label 'SalesHeader.FIND Count: ';
        Text001: Label 'Change to Sales Order or Credit Memo Payment Method Code\';
        Text002: Label 'The Count: ';

}

after launch: debug5 debug6 debug12 debug7 debug8 debug9

settings.json

{
    "workbench.iconTheme": "vscode-icons",
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "editor.renderControlCharacters": false,
    "files.autoSave": "afterDelay",
    "editor.wordWrap": "on",
    "workbench.colorTheme": "Default Light+",
    "editor.selectionHighlight": false,
    "editor.occurrencesHighlight": false,
    "window.zoomLevel": 0,
    "spellright.documentTypes": [

        "markdown",
        "latex",
        "plaintext"
    ],
    "spellright.ignoreFiles": [

        "**/.gitignore",
        "**/.spellignore"
    ],
    "spellright.language": [

    ],
    "spellright.languageContext": {

    },
    "cSpell.userWords": [
        "Mgmt",
        "Packt",
        "Walkthrough"
    ],
    "workbench.sideBar.location": "left",
    "todo-tree.tree.showScanModeButton": false,
    "dashboard.projectData": null,
    "zenMode.centerLayout": false,
    "zenMode.fullScreen": false,
    "bdev-al-xml-doc.checkProcedureDocumentation": true,
    "al.enableCodeActions": true,
    "al.codeAnalyzers": [
    "${AppSourceCop}","${CodeCop}"
    ],
    "editor.fontSize": 12,
    "editor.lineHeight": 14,
    "debug.allowBreakpointsEverywhere": true,
    "al.editorServicesLogLevel": "Verbose"
}

.vscode\extensions directories that were updated yesterday (when working with the "al.editorServicesLogLevel": setting:

No subdirectories, not sure what,if anything, it has to do with debugging? debug13

Has subdirectories, later version, earlier time modified. debug14

apaGitHub commented 3 years ago

This issue was resolved on the Dynamics 365 Business Central/NAV User Group Developers Forum (Help needed: The Vs Code debugger (AL code) does not work; does not stop on breakpoints).

Apparently the issue revolved around web sessions. After clearing .alchache in VS Code and the browser cache, I also cleared the VS Code credentials cache and then canceled the session in Dynamics 365 Business Central admin center. I then signed in with new credentials, the app launched, and the debugger worked as expected.

No other changes were made. Since then, non of the above steps taken seem necessary, and the debugger works after F5 and then calling the subscription as previously noted.

mail2joh commented 2 years ago

Hi I got the same problem. All of a sudden debugging stopped to work. I also tried clear credentials and reload windows in VS code. That did not work. I tried to delete files in .alcache and .alpackages folder. That did not work. I also tried adding to settings.json: "debug.allowBreakpointsEverywhere": true, That did not work. Then I deleted browsing data in Edge web browser. clear credentials and reload windows in VS code. This seemed to work! /J