Repository navigation
Description
Describe the bug
The StaggeredLayout from the new namespace CommunityToolkit.WinUI.Controls.Primitives crashes on ARM64 build when used in an ItemsView with the following StackTace:
Message = "Array dimensions exceeded supported range."
at CommunityToolkit.WinUI.Controls.StaggeredLayout.MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
at Microsoft.UI.Xaml.Controls.VirtualizingLayout.Microsoft.UI.Xaml.Controls.IVirtualizingLayoutOverrides.MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
at ABI.Microsoft.UI.Xaml.Controls.IVirtualizingLayoutOverrides.Do_Abi_MeasureOverride_2(IntPtr thisPtr, IntPtr context, Size availableSize, Size* result)
Note that the sample app also crashes if you go to the StaggeredLayout page (IF you are on ARM64 device).
Regression
No response
Reproducible in sample app?
- This bug can be reproduced in the sample app.
Steps to reproduce
1. Build and run the sample app on ARM64.
2. Observe the crash.
Here's the link for the sample app: https://github.com/euju-ms/StaggeredLayoutArm64
The code basically uses the StaggeredLayout in ItemsView.
<ItemsView ...>
<ItemsView.Layout>
<tkControls:StaggeredLayout />
</ItemsView.Layout>
</ItemsView>
Expected behavior
Expected to see three items show up instead of crashing.
Screenshots
Following three blue squares should show when it works; but using the newest StaggeredLayout crashes the app immediately.
Windows Build Number
- Windows 10 1809 (Build 17763)
- Windows 10 1903 (Build 18362)
- Windows 10 1909 (Build 18363)
- Windows 10 2004 (Build 19041)
- Windows 10 20H2 (Build 19042)
- Windows 10 21H1 (Build 19043)
- Windows 11 21H2 (Build 22000)
- Other (specify)
Other Windows Build number
Windows 11 24H2 (Build 26100.1742)
App minimum and target SDK version
- Windows 10, version 1809 (Build 17763)
- Windows 10, version 1903 (Build 18362)
- Windows 10, version 1909 (Build 18363)
- Windows 10, version 2004 (Build 19041)
- Other (specify)
Other SDK version
No response
Visual Studio Version
2022
Visual Studio Build Number
Version 17.11.3
Device form factor
Desktop
Nuget packages
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240829007" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
Additional context
I set WindowsSdkPackageVersion of 10.0.22621.45 for WinAppSdk 1.6 to work (but I verified that the issue persists without this in WinAppSdk 1.5.240802000).
I have also verified that the StaggeredLayout from the old package CommunityToolkit.WinUI.UI.Controls version 7.1.2 works.
Help us help you
No.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done

Activity
euju-ms commentedon Sep 24, 2024
Just updated the original post to say that the sample app crashes if you go to StaggeredLayout page from ARM64 device.
Here's the log message from Event Viewer
Arlodotexe commentedon Nov 13, 2024
@michael-hawker any ideas here?
michael-hawker commentedon Nov 27, 2024
@Arlodotexe I think the only change here has been #371 and the update of the underlying WindowsAppSDK. PowerToys was seeing this as well: microsoft/PowerToys#35139 - reverting back to 8.0 - though they said they also saw it on x64. (The UWP sample app from the store is running for me though on my x64 box.)
I don't have immediate access to an ARM64 device though for testing. It's odd that it'd be architecture specific here.
@euju-ms can you try the latest 8.2-preview on NuGet we have and see if that changes anything? For the sample gallery, are you referring to the one directly from the store or did you build it locally? As the store build is UWP, which would indicate it's across framework and maybe something in our code then.
Otherwise, based on the error message pointing out arrays, and only one main code change happening, I would wonder if it has something to do with the change to this logic here from #371:
Windows/components/Primitives/src/StaggeredLayout/StaggeredLayout.cs
Lines 161 to 181 in e3cd8ec
And it's downstream effect here:
Windows/components/Primitives/src/StaggeredLayout/StaggeredLayout.cs
Lines 217 to 281 in e3cd8ec
But in the default case, as far as I can tell, this should behave the same between 8.0 and 8.1...
@Poker-sang you wouldn't happen to have an ARM64 device would you and able to assist in debugging this issue?
I was able to test on my x64 machine and see that things work fine for both UWP and Uno WASM here, though hitting a different AOT related issue on main now for testing WinUI 3 (with setting ItemsSource), so I'm trying to resolve that first to continue testing. See #517, CommunityToolkit/Tooling-Windows-Submodule#213, #516.
michael-hawker commentedon Nov 27, 2024
Updating to CSWinRT 2.1.6 allows me to run the StaggeredLayout sample on my x64 machine again, submitting a PR for that to the Tooling repo: CommunityToolkit/Tooling-Windows-Submodule#232
Poker-sang commentedon Nov 27, 2024
sorry i don't have an arm64 machine🤕
Poker-sang commentedon Nov 28, 2024
I am totally sorry. I mistakenly moved
before
state.ColumnWidth's assginment. That's a stupid bug. And not always appears. I fixed it along with #574michael-hawker commentedon Nov 28, 2024
@Poker-sang thanks for jumping in here and taking a look. 🦙❤️ I see that now, definitely easy to miss.
Thank you for submitting a fix so quickly. This explains the inconsistency we may have been seeing in reproducing the issue. We'll help sort out and review the PRs after the holiday weekend here next week and get them into the next preview for 8.2.
euju-ms commentedon Dec 2, 2024
@michael-hawker
CommunityToolkit.WinUI.Controls.Primitives 8.2.241112-preview1in my sample test app, but it still crashes.The Windows Community Toolkit Gallery appcrashes when I go to the StaggeredLayout page. This is the store build :(michael-hawker commentedon Dec 2, 2024
@euju-ms no worries, looks like we have a fix incoming, which we haven't merged yet. It should be in the next preview that we'll hopefully push up to NuGet later this week 🤞.
DaveAurionix commentedon Jul 19, 2025
Is this bug back? I'm using CommunityToolkit.Uwp.Controls.Primitives 8.2.250402 on arm64 and get this exception frequently.
When looking at the source code at https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/main/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredPanel/StaggeredPanel.cs, I'm not clear on what happens if availableWidth is infinite - is numColumns left at a stupendously high value? availableWidth is set to totalWidth when infinity is detected, but numColumns is not adjusted and that makes me suspicious. If that is the issue, I wonder if unit tests around MeasureOverride itself are appropriate to stop this reoccurring maybe? I couldn't quickly figure out the test strategy in the whole toolkit though so that might not be a good question.
Ahh ... some issues happen when availableSize is infinite, and then more if HorizontalAlignment is HorizontalAlignment.Stretch as well as the size being infinite.