Skip to content

test: Guard span data alignment in Uno assemblies - #25630

Open
agneszitte wants to merge 1 commit into
masterfrom
dev/agzi/span-data-alignment-test
Open

agneszitte wants to merge 1 commit into
masterfrom
dev/agzi/span-data-alignment-test

Conversation

@agneszitte

Copy link
Copy Markdown
Member

GitHub Issue: Related to #25626 (this guards against it coming back; the 6.7 fix itself is the backport #25627)

PR Type:

🏗️ Build or CI related changes

What changed? 🚀

Adds a unit test that fails when constant span data in Uno's assemblies isn't aligned.

  • Why: a constant span like Split(':', '.') is read from static data the compiler aligns to its element size. In Release, the build rewrites the compiled assembly (EmbeddedResourceInjectorTask), and Mono.Cecil 0.11.4 dropped that alignment. CoreCLR only checks it when JIT optimizations are off, so 6.7 apps broke only under a debugger (6.7 desktop apps break under the debugger: "The field is invalid for initializing array or span" #25626). No test could see it.
  • What the test does:
    • Reads every __StaticArrayInitTypeSize=N_Align=M field of Uno's assemblies through RuntimeHelpers.CreateSpan<byte>, and fails if its address isn't a multiple of M.
    • Includes fixed span data in the test assembly itself (2-, 4- and 8-byte aligned, mixed with odd-sized blobs). That assembly goes through the same rewrite, so the check doesn't depend on what Uno.UI happens to contain.
    • Fails if the rewrite didn't run (no injected ILLink.Substitutions.xml). In Debug, where nothing is rewritten, it reports Inconclusive.
  • Covers: the Release unit-test build on CoreCLR, which CI runs. It doesn't cover the WebAssembly or mobile builds, which have their own data layout.
  • No product change.

Reviewer's guide

  • Start here: src/Uno.UI.UnitTests/Assemblies/Given_StaticDataAlignment.cs.
  • Test that proves it (local, .NET 11 rc.1 SDK from build/ci/net11/_global.json, Uno.UI-UnitTests-only.slnf built in Release):
    • Passes on this branch.
    • Fails when the test assembly is rewritten with Mono.Cecil 0.11.4 (5 of the 9 fixture fields misaligned, each listed with its field name and offset).
    • The first version, without fixture data, also failed on a Uno.UI.dll rewritten with 0.11.4.
    • Reports Inconclusive in Debug.
    • Full unit-test suite: same results with and without this test (13 date/calendar tests fail locally either way; they depend on the machine's time zone).
  • Watch for: Uno's assemblies are found by matching Uno.UI's assembly version (src/Directory.Build.props), so third-party dependencies aren't checked.
  • Next: once chore: use Mono.Cecil 0.11.6 (backport #24050) #25627 is merged, this test should also go to release/stable/6.7 (and servicing/6.8).

PR Checklist ✅

  • 🧪 Added a unit test
  • 📚 Docs have been added/updated (not needed: test only)
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests

🤖 Generated with Claude Code

A post-compile rewrite of the built assembly (Mono.Cecil 0.11.4 in
EmbeddedResourceInjectorTask) dropped the alignment of constant span
data in Uno.UI.dll. CoreCLR only checks it when JIT optimizations are
off, so 6.7 apps broke only under a debugger and no test noticed.

The test reads every aligned span data field of Uno's assemblies,
including fixed data in the test assembly, which goes through the same
Release rewrite, and fails when one isn't aligned. It also fails when the
rewrite didn't run, and is inconclusive in Debug, where nothing is
rewritten.

Related to #25626

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @agneszitte's task in 15s —— View job


Review summary

Verdict: ship. This is a test-only change. It's well scoped and the rationale is clear.

Issues: 0 high, 0 medium, 1 minor (inline: Assert.Inconclusive in Debug).

Code review assessment (by inspection only; I did not build or run it):

  • Conventions are followed: [UITestClass], Given_/When_ naming, [GitHubWorkItem] link, tabs, braces, file-scoped namespace, #nullable enable.
  • The Pack > 1 filter correctly selects only __StaticArrayInitTypeSize=N_Align=M types.
  • Reading the data as byte spans avoids throwing, so every misaligned field gets listed.
  • The fixture AlignedData keeps the test independent of what Uno.UI happens to contain, and the "found in test assembly" assertion guards against the test silently checking nothing.
  • The Release path fails when the rewrite didn't run, which prevents a false green.

Cross-cutting notes:

  • Uno assemblies are matched by Uno.UI's assembly version. If a Uno assembly ever has a different version, it would be skipped silently. That's acceptable as documented.
  • Coverage is limited to CoreCLR unit tests, as the description states. WASM and mobile are not covered.
  • No runtime validation was done on my side.

if (!testAssembly.GetManifestResourceNames().Contains("ILLink.Substitutions.xml"))
{
#if DEBUG
Assert.Inconclusive("Only Release builds rewrite assemblies after compile; run this test in Release.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo review rules flag Assert.Inconclusive, and in Debug this test always ends up Inconclusive, so it checks nothing there. The reasoning is sound, since Debug builds aren't rewritten and so there's nothing to verify. The author documents it in the PR description, so I'd treat this as a minor/accepted trade-off. If you'd rather not have a permanently inconclusive test, consider excluding the test with #if !DEBUG around the whole method. Otherwise keep it as is, since Release is what CI runs.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 240699 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DropDownButtonPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 2458 changed over 2490

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedIconPage.png
    • AppBarToggleButtonTest.png-dark
    • AnimatedVisualsTestbedPage.png
    • ApplicationViewSpanningRectsPage.png
    • AppBar_KeyBoard.png-dark
    • AppWindowTitleBar Properties.png
    • ApplicationViewSpanningRectsPage.png-dark
    • Attributed_text_FontSize_Changing.png
    • AppWindowPositionAndSize.png-dark
    • AutoBorderStretchwithbottommargin.png-dark
    • ArcSegment.png-dark
    • AutomationProperties_Landmark.png-dark
    • Attributed_text_Supserscript.png
    • AutomationProperties_StructureAndProps.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoSuggestBox_Reason.png-dark
    • AutomationPropertiesExtensions_Role.png
    • AutoSuggestBox_Reason.png
    • AutomationProperties_AutomationId.png-dark

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6.7 desktop apps break under the debugger: "The field is invalid for initializing array or span"

4 participants