Repository navigation
Description
Background
While building #43, src/AppShell.xaml referenced an icon that does not exist:
Glyph="{x:Static icons:FluentIconsRegular.Compass24}"The build was completely clean:
Build succeeded.
0 Warning(s)
0 Error(s)
The app then crashed the moment it launched:
android.runtime.JavaProxyThrowable: [Microsoft.Maui.Controls.Xaml.XamlParseException]:
Position 30:34. No static member found for icons:FluentIconsRegular.Compass24
at Microsoft.Maui.Controls.Xaml.XamlLoader.Load
at AniSprinkles.AppShell.InitializeComponent
at AniSprinkles.App.CreateWindow
The real member is CompassNorthwest24. IconFont.Maui.FluentIcons 1.1.0 has CompassNorthwest24 and CompassTrueNorth24, but no plain Compass24.
Problem
x:Static is resolved by the XAML loader at runtime, not verified at compile time, so a misspelled icon name is invisible until the page actually loads. tests/AniSprinkles.UnitTests/XamlFileValidationTests.cs does not help — it runs XDocument.Load over every .xaml, which only proves the file is well-formed XML. Compass24 is perfectly well-formed; it is just a name that does not exist.
This one was lucky: the bad glyph was in AppShell.xaml, which loads at startup, so it failed immediately and unmissably. The same typo on FeedPage or StudioDetailsPage would build clean, pass tests, pass CI screenshots, and only crash when a user opens that specific screen.
Goal
A unit test that scans every src/**/*.xaml for icons:FluentIconsX.Name references and fails if any does not resolve against the icon assembly.
Implementation notes
Follow the structure of XamlFileValidationTests.cs — it already enumerates every .xaml under src/ (excluding /bin/ and /obj/) and has a FindRepoRoot() helper.
The awkward part: the test project targets plain net10.0 while the icon assembly targets net10.0-android36.0, so it cannot be project-referenced and Assembly.Load will fail. Read the PE metadata directly instead:
using var fs = File.OpenRead(dllPath);
using var pe = new PEReader(fs);
var md = pe.GetMetadataReader();
// walk md.TypeDefinitions for types named FluentIcons*, enumerate GetFields()This approach is verified working — it correctly reports Search24, Person24, List24, ArrowSortUpLines24 and AppsList24 as present, and Compass24 as absent.
Two traps worth avoiding, both of which produced confidently wrong answers on the way to the above:
- Substring matching the DLL reports
Compass24as present, becauseCompassNorthwest24contains it. - Regex over the metadata
#Stringsheap silently misses every other name, because entries are stored back-to-back sharing NUL delimiters —\x00(name)\x00consumes the separator the next name needs.
Resolve the package path from the restore graph rather than hardcoding a profile path, and skip the test gracefully if the assembly cannot be located, so it does not break on another machine or a version bump.
Relationship to #65
Related but not the same, and worth reading together.
#65's option 2 — fail the CI screenshot job on JavaProxyThrowable / startup crashes found in logcat — would have caught this specific crash as a side effect, since XamlParseException surfaces exactly that way and produces the same symptom #65 describes: a screenshot job that "succeeds" while the app never rendered.
The difference is where the two catch it:
- Add startup DI-resolution smoke test to catch missing registrations #65 catches runtime explosions at CI time, after a full MAUI build and an emulator boot (~20-30 min), and only on the screens the screenshot flow actually visits.
- This one is a static check that runs in
dotnet testin milliseconds, covers every XAML file including pages CI never opens, and names the offending file, line and member.
Doing #65 first would meaningfully reduce the urgency here. Doing both is cheap and they fail at different distances from the mistake.
Acceptance
- A unit test exists that fails if any
x:Staticicon reference insrc/**/*.xamldoes not resolve. - Temporarily reintroducing
Compass24makes it fail, with a message naming the file and the bad member. dotnet teststays green otherwise (391 tests at time of writing).
Activity
zhollis21 commentedon Aug 22, 2026
A follow-on from implementing this, worth recording here since it is this test's own failure mode.
The graceful skip is right — a machine that has not restored, or a version bump not yet pulled, should not fail red. But it means this test can stop checking without anyone noticing. That happened during #62: the package version is resolved by reading the app csproj, and when the app project moved from
src/AniSprinkles.csprojtosrc/AniSprinkles/AniSprinkles.csproj, all 190 cases turned into silent skips. Locally that showed asPassed: 413, Skipped: 190; CI would have reported a green tick.Two things came out of it:
src/**/*.csprojrather than naming one file, and a missing package declaration throws instead of skipping — that is a repo-structure problem, not the environmental gap the skip exists for. Only an unresolvable package cache still skips.Extract AniSprinkles.Core so PageModels can be tested (#62, #117) (#123)
Extract AniSprinkles.Core so PageModels can be tested (#62, #117) (#123)