Skip to content

MapChanged Event Raises Null args in WinUI 3 with ApplicationData.LocalSettings.Values #1988

Open
@cdaylin

Description

@cdaylin

Summary:
In a WinUI 3 app using ApplicationData.Current.LocalSettings.Values.MapChanged, the MapChanged event occasionally fires with a null args parameter, causing a NullReferenceException when accessing args.CollectionChange.

Expected behavior:
The IMapChangedEventArgs parameter (args) should never be null. All values should be non-null per WinRT metadata contracts.

Environment:

WinUI version: Microsoft.WindowsAppSDK 1.5 (or applicable version)

SDK / runtime: Microsoft.Windows.SDK.NET, WinRT.Runtime

.NET version: .NET 8

Platform: Windows 11

Architecture: x64

Repro Steps:

Subscribe to MapChanged:

ApplicationData.Current.LocalSettings.Values.MapChanged += HandleBackingPropertySetChanged;

Assign a value:

ApplicationData.Current.LocalSettings.Values["Temperature"] = 0.75;

In your handler:

private void HandleBackingPropertySetChanged(
    IObservableMap<string, object> sender,
    IMapChangedEventArgs<string> args)
{
    // This line throws unexpectedly
    switch (args.CollectionChange) { ... }
}

Observe args == null and resulting NullReferenceException.

Notes:

args is normally a WinRT-projected value and should never be null.

This seems to originate from Do_Abi_Invoke(...) in the auto-generated interop.

Bug occurs only occasionally, likely due to ABI event wiring edge case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions