Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Tests run from VS Code Test Explorer / altool runtests crash with NullReferenceException in NavClientHandle.Dispose after Camera.IsAvailable() (Item Card, Customer Card) – pass in AL Test Tool

Open
#8,343 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
vscode

Research direction

Start with codeunit 50100 and run its four reproductions through altool runtests and the VS Code Test Explorer, comparing them with the AL Test Tool. Inspect the Camera.IsAvailable() path and the Item Picture and Customer Picture page behavior described in the issue. Done means all four tests complete without the NavClientHandle.Dispose NullReferenceException when no client is attached.

Written by the indexing model from the issue text.

Description

input-needed

1. Describe the bug

Tests that pass in the AL Test Tool (page 130451) fail when they are run with the developer tools' test execution, i.e. the VS Code Test Explorer or altool runtests (no AL test runner). The failure is a platform exception while a page is disposed:

Unexpected CLR exception thrown.: System.NullReferenceException: Object reference not set to an instance of an object. in NavClientHandle.Dispose.

It occurs as soon as Camera.IsAvailable() has been called – directly, or indirectly by opening a card page whose picture FactBox calls it in OnOpenPage ("Item Picture" on the Item Card, "Customer Picture" on the Customer Card). As a consequence, every test that opens one of these card pages as a TestPage cannot be run from the Test Explorer or with altool runtests.

2. To Reproduce

  1. Create an app that depends on Microsoft apps only and add the codeunit below.
  2. Publish it to a BC 28.5 on-premises container that contains Microsoft apps only.
  3. Run codeunit 50100 with altool runtests 50100 --server https://<container> --serverinstance BC --port 7049 --tenant default --environmenttype OnPrem --authentication UserPassword --company "CRONUS International Ltd." (or from the VS Code Test Explorer).
  4. Run the same codeunit in the AL Test Tool (page 130451) in the web client.
codeunit 50100 "Camera Dispose Repro"
{
    Subtype = Test;
    TestPermissions = Disabled;

    [Test]
    procedure "01_Control_OpenAndClosePaymentTerms"()
    var
        PaymentTerms: TestPage "Payment Terms";
    begin
        PaymentTerms.OpenView();
        PaymentTerms.Close();
    end;

    [Test]
    procedure "02_CameraIsAvailableWithoutAnyPage"()
    var
        Camera: Codeunit Camera;
    begin
        if Camera.IsAvailable() then;
    end;

    [Test]
    procedure "03_OpenAndCloseItemCard"()
    var
        ItemCard: TestPage "Item Card";
    begin
        ItemCard.OpenView();
        ItemCard.Close();
    end;

    [Test]
    procedure "04_OpenAndCloseCustomerCard"()
    var
        CustomerCard: TestPage "Customer Card";
    begin
        CustomerCard.OpenView();
        CustomerCard.Close();
    end;
}

3. Expected behavior

Same result as in the AL Test Tool: all four tests pass. For example, Camera.IsAvailable() could return false (or not create the client-side object) when no client is attached, so that the page and codeunit can be disposed.

4. Actual behavior

Test altool runtests (no test runner) AL Test Tool (page 130451)
01_Control_OpenAndClosePaymentTerms pass pass
02_CameraIsAvailableWithoutAnyPage FAIL pass
03_OpenAndCloseItemCard FAIL pass
04_OpenAndCloseCustomerCard FAIL pass

Error of 02 (03 and 04 end in the same frames, reached via the picture FactBox of the card):

Unexpected CLR exception thrown.: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Dynamics.Nav.Runtime.NavClientHandle.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.Runtime.NavInteropHandleReferenceCount.Dispose()
   at Microsoft.Dynamics.Nav.Runtime.NavDotNet.Clear()
   at Microsoft.Dynamics.Nav.Runtime.NavDotNet.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.Runtime.NavForm.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.Runtime.TreeHandler.TreeObjectReferenceHandler.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.Runtime.NavFormHandle.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.Runtime.TreeHandler.Dispose(Boolean disposing)
   at Microsoft.Dynamics.Nav.BusinessApplication.Codeunit50100._02_CameraIsAvailableWithoutAnyPage()

Analysis from the source (Base Application / System Application 28.5):

  • "Item Picture" OnOpenPage: CameraAvailable := Camera.IsAvailable(); (same pattern in "Customer Picture").
  • "Camera Impl." IsAvailable() only checks GuiAllowed() – which is true in test sessions – and then calls page "Camera".
  • Page "Camera" holds [RunOnClient] [WithEvents] CameraProvider: DotNet CameraProvider;.

Without an attached client there seems to be no valid client handle when this RunOnClient object is disposed. There is no way for a test to intercept before the DotNet call (OnIsCameraAvailable is raised afterwards).

5. Versions:

  • AL Language: 18.0.2732683
  • Visual Studio Code: 1.139.1
  • Business Central: on-premises Docker container, platform 28.0.54423.0, Base Application 28.5.54151.54491 (company CRONUS International Ltd.); only Microsoft apps installed besides the repro app
  • List of Visual Studio Code extensions that you have installed: not relevant for the repro above – it was run with altool runtests outside VS Code. The same exception occurs for our own test codeunits in the VS Code Test Explorer.
  • Operating System:
    • Windows
    • Linux
    • MacOS
Final Checklist
  • Search the issue repository to ensure you are reporting a new issue (related, but different: #8233, #8254)
  • Reproduce the issue after disabling all extensions except the AL Language extension (reproduced with altool runtests, no VS Code extensions involved)
  • Simplify your code around the issue to better isolate the problem
Dominant language
PowerShell
Stars
882
Forks
284
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/AL

All issues in microsoft/AL

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.