Skip to content

ApplicationView.GetApplicationViewIdForWindow throws; a sentinel would let WinUI code run unmodified #24288

Open

Description

@MartinZikmund

What happened

ApplicationView.GetApplicationViewIdForWindow throws NotImplementedException rather than returning a sentinel.

Source

src/Uno.WinRT/Generated/3.0.0.0/Windows.UI.ViewManagement/ApplicationView.cs:183 (verified on feature/breakingchanges):

public static int GetApplicationViewIdForWindow(global::Windows.UI.Core.ICoreWindow window)
{
    throw ...CreateNotImplementedException("Windows.UI.ViewManagement.ApplicationView", "GetApplicationViewIdForWindow(ICoreWindow window)");
}

Why it matters

The method returns an opaque int used to tag per-window state — telemetry, view bookkeeping, multi-window dictionaries. Callers almost never branch on the value, so on a single-window platform a constant would be entirely serviceable.

Because it throws, otherwise-portable code has to be modified. Worse, the common call sites sit inside dispatcher continuations:

await Dispatcher.RunAsync(..., () => {
    var id = ApplicationView.GetApplicationViewIdForWindow(window);   // throws
    refThis.GetMemory();                                             // never runs
});

There the exception is unobserved — no crash, but everything after it in the continuation is silently skipped, producing a feature that simply does nothing with no diagnostic. In microsoft/calculator this pattern appears in ApplicationViewModel, Utils.GetWindowId(), Calculator.xaml.cs and MainPage.xaml.cs.

Expected

Return a stable sentinel (e.g. -1, or a per-window id) instead of throwing, consistent with how other single-window view APIs degrade. That alone would let a large amount of upstream WinUI code run unmodified.

Notes

Found while porting microsoft/calculator to Uno 7. Verified against feature/breakingchanges.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions