Skip to content

Fix null URI handling in generated dependency property setters - #818

Merged
Sergio0694 merged 2 commits into
mainfrom
user/sergiopedri/null-uri-setters
Sep 24, 2026
Merged

Sergio0694 merged 2 commits into
mainfrom
user/sergiopedri/null-uri-setters

Conversation

@Sergio0694

@Sergio0694 Sergio0694 commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Generated Uri setters currently call XamlBindingHelper.SetPropertyFromUri unconditionally, but the native helper rejects a null value. This affects both Uri? properties and non-nullable properties that receive null at runtime, including values replaced by a typed setter hook.

  • Fall back to SetValue(Property, value) for null URIs, retaining the optimized helper for non-null values in both caching modes and both XAML namespaces. The check runs after the typed set hook; caching, change hooks, and dependency-property callback ordering are preserved.
  • Keep Fix optimized DP setter codegen for 'string' properties #794's null/empty string fallback. Select the fallback by the enabled helper rather than the property type, also fixing cached string setters bypassing an implemented boxed set hook.
  • Add full generated-output regression tests using the existing VerifySources helper, and update the component documentation. No ClearValue, skipped null assignments, projection-version changes, or application-specific workarounds are introduced.

XamlBindingHelper null audit

Audited every helper selection and both setter emitters. The SetPropertyFrom prefix is omitted in this table. Native entry-point checks are visible in the WinUI implementation.

Helper(s) Finding and generated behavior
Uri Rejects null. This change adds the SetValue fallback, independently of nullable annotations, after typed hooks have run.
String Rejects null and empty strings. Preserve the existing fallback; do not enter the optimized path when a boxed set hook disables it.
Object Also rejects null, but the generator explicitly disables this helper for object properties. Both emitters already use SetValue.
Boolean, Byte, Char16, Double, Int32, Int64, Single, UInt32, UInt64 Non-nullable value parameters cannot receive null. Nullable counterparts do not match the helper selection and use SetValue.
DateTime, TimeSpan, Point, Rect, Size Likewise use non-nullable value parameters. Nullable counterparts use SetValue.
Color, CornerRadius, Thickness Non-nullable value parameters, available only through the existing WinUI API/signature probe. UWP and nullable counterparts use SetValue.

An implemented boxed setter hook disables typed helpers so it can inspect or replace the boxed value. The cached string special case was the exception; this PR brings it back in line with the other paths. No other emitted helper needs an additional null fallback.

Regression coverage

The added tests follow the existing source-generator test pattern: provide the input source and compare the entire generated output with VerifySources. They cover Uri/Uri?, both caching modes, typed hooks assigning null, and boxed hooks for nullable/non-nullable URI and string properties. Existing string null/empty snapshots are preserved.

There is no added reflection, generated-code execution harness, managed XAML emulation, fragment matching, or shared test-helper modification in the PR.

Validation

  • 898 tests passed in the complete Release test project after the snapshot-only revision.
  • As a separate, one-off audit, a real native UWP XAML probe passed: direct URI/string/object helper rejection, generated Uri/Uri? transitions in both caching modes, hook-induced nulls and ordering, null/empty strings, object nulls, and explicit local-null storage rather than clearing the property. That execution harness is not part of the committed tests.
  • Native WinUI application execution and downstream application/PDP validation have not been performed. The audit above covers the WinUI helper signatures and generator paths.

Sergio0694 and others added 2 commits September 21, 2026 17:56
Guard optimized URI setters after typed hooks in both caching modes, preserve the string null/empty fallback and boxed set hooks, and audit all generated XAML helper paths with regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the runtime/reflection harness and fragment assertions with existing VerifySources snapshots. Cover URI null fallbacks, null-producing typed hooks, and boxed string/URI hooks without changing the shared test helpers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Sergio0694
Sergio0694 merged commit 8932813 into main Sep 24, 2026
23 of 24 checks passed
@Sergio0694
Sergio0694 deleted the user/sergiopedri/null-uri-setters branch September 24, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants