Repository navigation
fix(databinding): reject bindable metadata resolved across ALC boundaries - #24096
Conversation
…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.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24096/wasm-skia-net9/index.html |
dr1rrb
left a comment
There was a problem hiding this comment.
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.
|
Tick the box to add this pull request to the merge queue (same as
|
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.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24096/wasm-skia-net9/index.html |
fix(databinding): reject bindable metadata resolved across ALC boundaries (backport #24096)
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 toGetBindableTypeByFullName(type.FullName)). When the same assembly is loaded in a secondAssemblyLoadContext(a host application previewing a secondary app, per theUno.UI.RuntimeTestshosting pattern), a lookup for the secondary context's type returns the host context'sIBindableType— whose typed getters then throwInvalidCastException, and controls binding such types (e.g.FeedView'sFeedViewStateas a template DataContext) silently render blank.IBindableTypealready carries itsType, 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 inBindingPropertyHelper, andTypeActivator.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_UNObranch) and the name-based lookup inDependencyPropertyDescriptor(noTypeinput exists to validate against).Behavior notes:
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.IBindableMetadataProviderthat deliberately returns metadata whoseTypediffers 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 withInvalidCastExceptionon 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.InvalidCastExceptionFeedViewStatetyped getters via the host's bindable metadata providerFeedViewrenders blankUno.Extensions.Reactive(.UI/.Messaging)from the host ALC (shared identity)B also only works at all when host and secondary app carry byte-identical
Uno.Extensionsversions, which a host cannot guarantee; C fixes the lookup for any same-named type across contexts with no host cooperation.PR Checklist ✅
Screenshots Compare Test Runresults.