Skip to content

Fix TableView NullReferenceException in trimmed (Store) builds - #2265

Merged
Niels Laute (niels9001) merged 1 commit into
mainfrom
niels9001-fix-tableview-nullref
Oct 7, 2026
Merged

Niels Laute (niels9001) merged 1 commit into
mainfrom
niels9001-fix-tableview-nullref

Conversation

@niels9001

Copy link
Copy Markdown
Collaborator

Description

Marks TableViewSampleItem as partial (public sealed partial class).

Motivation and Context

In the 3.0 Store flight, opening the TableView page shows an empty page and a System.NullReferenceException. Debug builds work fine.

TableViewSampleItem implements INotifyPropertyChanged and INotifyDataErrorInfo, and it is marshalled to native code through TableViewSource.From(...). Because the class wasn't partial, CsWinRT built its CCW vtable at runtime through reflection (ComWrappersSupport.GetInterfaceTableEntriesForJitEnvironment → TypeExtensions.GetAbiToProjectionVftblPtr). Published/Store builds are trimmed (PublishTrimmed=$(Optimized)), and the trimmer removed the ABI helper type that lookup needs, so it threw a NullReferenceException in the TableViewPage constructor.

Making the class partial lets the CsWinRT AOT source generator emit a static WinRTExposedType vtable that survives trimming. Other gallery models that are exposed to WinRT follow the same pattern.

How Has This Been Tested?

  • Before the fix: published a trimmed Release-Unpackaged x64 build (msbuild WinUIGallery\WinUIGallery.csproj /restore /t:Publish /p:Configuration=Release-Unpackaged /p:Platform=x64), opened TableView, and reproduced the crash. The captured stack trace pointed to TableViewSource.From → GetAbiToProjectionVftblPtr.
  • After the fix: republished the same trimmed build (passed, no errors) and opened TableView. The page renders with all rows populated, the app keeps running, and no exception is raised.
  • Not tested: the arm64 Store package itself.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
TableViewSampleItem implements INotifyPropertyChanged and INotifyDataErrorInfo and is marshalled to native via TableViewSource. As a non-partial class, CsWinRT built its CCW vtable via reflection, which fails in trimmed (Store) builds. Marking it partial lets the CsWinRT AOT generator emit a static vtable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@niels9001
Niels Laute (niels9001) enabled auto-merge (squash) October 7, 2026 20:20
@niels9001
Niels Laute (niels9001) merged commit 47f54b4 into main Oct 7, 2026
4 checks passed
@niels9001
Niels Laute (niels9001) deleted the niels9001-fix-tableview-nullref branch October 7, 2026 22:27
Niels Laute (niels9001) added a commit that referenced this pull request Oct 7, 2026
## Description
Patch release 3.0.1 for the `release/3.0` branch:
- Cherry-picks #2265 (Fix TableView NullReferenceException in trimmed
(Store) builds), found during the 3.0.0 flight.
- Bumps the version to 3.0.1.0 (`WinUIGallery.csproj`,
`Package.appxmanifest`, `Package.Dev.appxmanifest`) and the Store
pipeline's default `releaseVersion` to 3.0.1.

## Motivation and Context
3.0.0.0 went out to the `WinUI Gallery 3.0 Flight` package flight, and
the TableView sample crashed in the trimmed Store build. Following
`docs/PublishingNewVersion.md` ("Fixing issues during the release"), the
fix landed on `main` first and is cherry-picked here with a patch bump,
so a new flight submission can be made from `release/3.0`.

## How Has This Been Tested?
- The fix was validated in #2265 (approved, merged to `main`).
- PRValidation runs on this PR.
- After merge, 3.0.1 will be published to the flight through the
Store-Release pipeline for testers to verify.

## Screenshots (if appropriate):
N/A

## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Niels Laute (niels9001) added a commit that referenced this pull request Oct 7, 2026
## Description
Cherry-picks #2266 (Enable mouse and touch inking in InkCanvas toolbar
and save/restore samples) into `release/3.0` for 3.0.1. No version bump
is needed: 3.0.1 (#2267) hasn't been built or submitted to the Store
yet.

## Motivation and Context
#2266 was merged to `main` and should ship in the 3.0.1 flight build
together with the TableView fix (#2265), following
`docs/PublishingNewVersion.md`.

## How Has This Been Tested?
- Validated in #2266 (approved, PRValidation passed, merged to `main`).
- The cherry-pick applied cleanly onto `release/3.0`, including
`catalog/windows-samples.json`.
- PRValidation runs on this PR.

## Screenshots (if appropriate):
N/A

## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Niels Laute (niels9001) pushed a commit that referenced this pull request Nov 7, 2026
#2283)

## Description

Adds three examples to the TableView page:

### 1. Showing hierarchical rows
- A flat folder/file collection (`TableViewHierarchyItem`, with `Id` and
`ParentId`) is shown as nested rows through
`TableViewSource.ParentBy(Id, ParentId)`. A null parent key makes a
top-level row.
- Options: a name filter (matches keep their ancestors, which stay
expanded while the filter is active), plus **Expand all rows** /
**Collapse all rows** (`ExpandAllRows` / `CollapseAllRows`).
- Keyboard: Right expands a row; Left collapses it or moves to the
parent; `*` expands the focused row's subtree.
- The Name column has `MinWidth="200"` so third-level names aren't
truncated by the indent.

### 2. Adding context menus to cells, rows, and headers
Shows how TableView chooses which menu to open:
- **Name cells:** a `CellContextFlyout` with "Copy name".
- **Other cells and rows:** the row's `ContextFlyout`, set through an
implicit `TableViewRow` style (Copy row / Move to next category /
Remove).
- **Column headers:** one `HeaderContextFlyout` shared by all columns.
Its `Opening` handler reads `MenuFlyout.Target`
(`TableViewColumnHeader.Column`) to offer "Hide <column>" (disabled on
the last visible column) and "Show all columns".
- **Everywhere else:** the table's own `ContextFlyout` ("Restore all
items") as the fallback.
- Menu items read their row from `DataContext`. Results go to the
example's Output.

### 3. Updating rows from live data
- A `DispatcherTimer` updates a few observable `TableViewLiveItem`
values every second, and the table is sorted by Value, descending.
- `TableViewSource.IsLiveShaping = true` re-applies the sort, filter,
grouping, and hierarchy on each `PropertyChanged`, so rows move as
values change and the selection stays with its row.
- A **Shaping** selector (Flat, Grouped by trend, Hierarchy, Grouped
hierarchy) shows live shaping on every projection: rows re-sort inside
their group or sibling set, move between Rising/Falling/Steady groups as
their change flips, and top-level rows keep their nested rows when they
move.
- Options: pause updates, turn live shaping off (cells still update but
rows stay in place), and filter to values of 50 or more (rows join and
leave as they cross 50).
- The timer starts and stops with the table's `Loaded` and `Unloaded`
events.

### Shared
- All new models are `partial`, per #2265, so trimmed Store builds keep
the CsWinRT vtable.
- `ControlInfoData.json`: adds `hierarchy`, `tree`, `context menu` and
`live data` tags, and updates the description.
`catalog/windows-samples.json` is regenerated.
- Tests:
  - The catalog test now expects 8 examples in order.
- New catalog tests cover the hierarchy, context menu, and live data
snippets.
- `SnippetMatchesThePageImplementation` fails if the three new snippets
stop matching `TableViewPage.xaml`, `TableViewPage.xaml.cs`, or the item
classes (only AutomationIds are left out of the snippets).
- New unit tests cover the hierarchy data (valid acyclic tree) and
`TableViewLiveItem` (tree shape, update, trend, clamping,
notifications).

## Motivation and Context

Follows #2250 (first set of TableView samples) by covering hierarchical
rows, context menus and live data updates, which TableView gained in
microsoft/microsoft-ui-xaml after #2250.

> [!IMPORTANT]
> **Blocked on the next Windows App SDK _experimental_ release.**
`ParentBy`, `ExpandAllRows`/`CollapseAllRows`,
`CellContextFlyout`/`HeaderContextFlyout`, and
`TableViewSource.IsLiveShaping` are not in `2.5.4-experimental`, so PR
validation fails to compile. The stable `2.6.4` release (27-Oct) doesn't
include them either, because TableView ships only in experimental
releases. All of these APIs are on the WinUI experimental release
branch. This PR deliberately does **not** change
`WindowsAppSdkPackageVersion`; the bump will be added when that release
ships.

## How Has This Been Tested?

Windows x64, .NET SDK 10.0.401, against a local build of
microsoft-ui-xaml `main` (466f4a35cb), referenced on top of
`2.5.4-experimental` with command-line-only overrides (no project files
in this PR change for that).

**Hierarchical rows**
- Initial tree, Expand all / Collapse all, and per-row expand via
`ExpandCollapsePattern` all work.
- Filtering: `jpg` keeps Pictures → Vacation → the two images, and `zzz`
shows the empty template.
- Keyboard: Right, `*` and Left (twice) behave as described.
- Checked visually in light and dark (screenshots below).

**Context menus** (opened through UI Automation `ShowContextMenu`, the
same path Narrator uses for Shift+F10)
- A Name cell opens the cell menu, and Copy name puts "Item 3" on the
clipboard.
- Category and Value cells open the row menu. Move to next category
changes Beta to Gamma, and Remove deletes the row.
- A header opens "Hide <that column>", and hiding works. On the last
visible column, Hide is disabled. Show all columns restores all three.
- The table itself opens the fallback menu, and Restore all items brings
back 5 rows.

**Live data**
- Starts sorted by Value, descending: the header reports "Sorted
descending".
- Rows stay sorted across updates, and the selected row stays selected
as it moves.
- Pause freezes the values.
- With live shaping off, the order drifts out of sort; turning it back
on re-sorts immediately.
- The ≥ 50 filter drops rows live as they fall below 50.
- Shaping: Grouped moves rows between trend groups live; Hierarchy keeps
parents and their children sorted; Grouped hierarchy moves a parent with
its children to its new trend group; switching back to Flat removes
groups and nesting. Filter in Hierarchy keeps matching rows with their
parent.
- Navigating away and back works, and updates resume.

**Builds and tests**
- **Trimmed publish:** `Release-Unpackaged` (`PublishTrimmed`, single
file). Hierarchy, all three menu levels, and live updates work with no
exception. The only trim warnings are pre-existing ones (`ItemPage`,
`WinRT.Runtime`).
- `dotnet test tests\WinUIGallery.CatalogExporter.Tests`: 172/172
passed. `CatalogExporter -- check`: index is up to date.
- `WinUIGallery.UnitTests` (TableView filter, through `vstest.console`):
20/20 passed.

## Screenshots (if appropriate):

Hierarchical rows. Screenshots of the context menu and live data
examples will be added with the package bump.

| Light, all rows expanded | Light, filter "jpg" |
| --- | --- |
| ![Light theme,
expanded](https://raw.githubusercontent.com/Nitin-100/WinUI-Gallery/b63393eefcc4fb8f11fef8fb233e729b1082e6e1/shot_light_expanded.png)
| ![Light theme,
filtered](https://raw.githubusercontent.com/Nitin-100/WinUI-Gallery/b63393eefcc4fb8f11fef8fb233e729b1082e6e1/shot_light_filter.png)
|

| Dark, keyboard focus on a nested row | Dark, no matches |
| --- | --- |
| ![Dark theme, focused nested
row](https://raw.githubusercontent.com/Nitin-100/WinUI-Gallery/b63393eefcc4fb8f11fef8fb233e729b1082e6e1/shot_dark_expanded.png)
| ![Dark theme, empty
state](https://raw.githubusercontent.com/Nitin-100/WinUI-Gallery/b63393eefcc4fb8f11fef8fb233e729b1082e6e1/shot_dark_empty.png)
|

## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

---------

Co-authored-by: Nitin Chaudhary <nitchaudhary@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants