Skip to content

fix(databinding): reject bindable metadata resolved across ALC boundaries - #24096

Merged
Kunal22shah merged 2 commits into
masterfrom
dev/ks/databinding-alc-metadata-identity
Aug 20, 2026
Merged

Kunal22shah merged 2 commits into
masterfrom
dev/ks/databinding-alc-metadata-identity

Conversation

@Kunal22shah

@Kunal22shah Kunal22shah commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24095 and https://github.com/unoplatform/studio.live/issues/3640

PR Type:

🐞 Bugfix

What changed? 🚀

Generated bindable metadata providers match types by full name (GetBindableTypeByType(type) delegates to GetBindableTypeByFullName(type.FullName)). When the same assembly is loaded in a second AssemblyLoadContext (a host application previewing a secondary app, per the Uno.UI.RuntimeTests hosting pattern), a lookup for the secondary context's type returns the host context's IBindableType — whose typed getters then throw InvalidCastException, and controls binding such types (e.g. FeedView's FeedViewState as a template DataContext) silently render blank.

IBindableType already carries its Type, so the binder now validates the lookup result against the requested type identity (BindingPropertyHelper.GetValidatedBindableType): a mismatch is treated as a miss and falls back to the reflection path — which is where non-colliding secondary-context types already resolved. A rejected mismatch is logged at Debug with both load-context names.

Covered call sites: BindablePropertyDescriptor.GetPropertByBindableMetadataProvider (named + attached properties), both indexer lookups in BindingPropertyHelper, and TypeActivator.CreateInstance (where a cross-context match would silently instantiate the other context's identically-named type). Known remaining raw provider sites, deliberately out of scope for a minimal fix: DirectUI/PropertyAccess.cs (HAS_UNO branch) and the name-based lookup in DependencyPropertyDescriptor (no Type input exists to validate against).

Behavior notes:

  • Single-ALC apps are unaffected: generated providers construct every entry with typeof(X), so the identity check never fires for them; hot-reload replacement types carry #N-suffixed names and never matched the name-keyed tables in the first place.
  • A custom IBindableMetadataProvider that deliberately returns metadata whose Type differs from the queried type would now be treated as a miss; generated providers never do this.

Tests: Given_Binder.MetadataProviderIdentity — matching-type pass-through, mismatched-type miss, and an end-to-end binding assertion that a poisoned cross-context getter is ignored in favor of the reflected value (fails with InvalidCastException on the previous code).

Verification (secondary-ALC host, FeedView repro)

Three variants were run against the same repro: a host app loading a prebuilt secondary app (using MVUX FeedView) into a collectible ALC.

Variant InvalidCastException Page creation / rendering Verdict
A - baseline (unpatched 6.7.16) Thrown in FeedViewState typed getters via the host's bindable metadata provider Pages create, but every FeedView renders blank Bug reproduced
B - host-side workaround: load Uno.Extensions.Reactive(.UI/.Messaging) from the host ALC (shared identity) Gone Page creation fails outright - navigation errors and XAML instantiation returning null (Reactive.UI registers its XAML resources per load context) Rejected - strictly worse
C - this fix: identity-validated metadata lookup + reflection fallback Gone All pages render fully, 0 navigation failures, transient converter noise gone Shipped

B also only works at all when host and secondary app carry byte-identical Uno.Extensions versions, which a host cannot guarantee; C fixes the lookup for any same-named type across contexts with no host cooperation.

PR Checklist ✅

…ries

Generated bindable metadata providers match types by full name, so when
the same assembly is loaded in a second AssemblyLoadContext (a host
application previewing a secondary app), a lookup for the secondary
context's type returns the host context's IBindableType. Its typed
getters then throw InvalidCastException and controls binding such types
(e.g. FeedView's FeedViewState) silently render blank.

Validate the provider result against the requested type identity:
IBindableType already carries its Type, so a mismatch now falls back to
the reflection path instead of returning foreign metadata.
Copilot AI lite review requested due to automatic review settings August 17, 2026 19:52

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Aug 17, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@Kunal22shah
Kunal22shah requested review from dr1rrb and kazo0 August 19, 2026 18:05

@dr1rrb dr1rrb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving — the fix is correct, minimal and well-scoped. The identity check (bindableType.Type != type, reference equality) is exactly the right semantics: within one ALC a type has a single RuntimeType instance, across ALCs they differ, so it can neither false-positive nor false-negative. Generated providers key by exact FullName and build each entry with typeof(X), so the guard never fires in single-ALC apps. The end-to-end test (poisoned cross-context getter ignored in favor of reflection) genuinely fails on the previous code. 👍

Two non-blocking notes — feel free to address the first inline and file a follow-up for the second:

1. Test isolation (address now if applicable). RunWithProvider mutates the static BindingPropertyHelper.BindableMetadataProvider and calls ClearCaches(). The restore-in-finally is clean, but it relies on this class not running concurrently with other binder tests that touch the same static state / caches. If Uno.UI.UnitTests parallelizes at the class/method level, this can flake. Historically these binder tests aren't parallelized so it's probably fine — but worth confirming, or adding [DoNotParallelize] on the class for safety.

2. Out-of-scope provider sites (follow-up issue). The two sites documented as deliberately out of scope — DirectUI/PropertyAccess.cs (HAS_UNO branch) and the name-based lookup in DependencyPropertyDescriptor — can reproduce the same class of bug through a different path. Leaving them out of a minimal fix is the right call, but let's open a tracking issue so it doesn't get rediscovered without context later.

@mergify

mergify Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

RunWithProvider swaps the static BindingPropertyHelper.BindableMetadataProvider
and clears the binder caches, so concurrent execution with other tests touching
that shared state could flake. [DoNotParallelize] pins the historical serial
behavior explicitly instead of relying on it.
Copilot AI review requested due to automatic review settings August 19, 2026 20:45

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Kunal22shah
Kunal22shah enabled auto-merge August 19, 2026 20:46
@unodevops

Copy link
Copy Markdown
Contributor

@Kunal22shah
Kunal22shah merged commit 758a96b into master Aug 20, 2026
51 checks passed
@Kunal22shah
Kunal22shah deleted the dev/ks/databinding-alc-metadata-identity branch August 20, 2026 13:40
agneszitte added a commit that referenced this pull request Nov 9, 2026
fix(databinding): reject bindable metadata resolved across ALC boundaries (backport #24096)
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.

[Skia] InvalidCastException in bindings when the same assembly is loaded in a second AssemblyLoadContext

5 participants