Skip to content

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

Closed

Description

@Kunal22shah

Current behavior

In a host application that loads a secondary app into a collectible AssemblyLoadContext (sharing Uno.UI with the host, per the Uno.UI.RuntimeTests hosting pattern), data binding fails with an InvalidCastException for any type whose full name exists in both load contexts:

System.InvalidCastException: [A]Uno.Extensions.Reactive.UI.FeedViewState cannot be cast to
[B]Uno.Extensions.Reactive.UI.FeedViewState.
Type A originates from 'Uno.Extensions.Reactive.UI' in the context 'AppALC-…' …
Type B originates from 'Uno.Extensions.Reactive.UI' in the context 'Default' …
   at MetadataBuilder_NNN.GetError(Object instance, …)  // generated BindableMetadata
   at Uno.UI.DataBinding.BindingPath.BindingItem.GetSourceValue(…)

The visible symptom: any FeedView (or other control binding such a type as its template DataContext) in the secondary app renders blank, with a build that is completely clean.

Root cause

BindingPropertyHelper.BindableMetadataProvider is a process-wide slot, and generated providers match types by full name (GetBindableTypeByType(type) → GetBindableTypeByFullName(type.FullName)). When the host registers its own generated provider and the secondary ALC contains an identically-named type, the provider returns the host's IBindableType — whose typed getters cast to the host context's type and throw.

The generated App.InitializeComponent does contain a secondary-ALC branch that nulls the provider, but it does not run under this hosting model (the host constructs the app directly), and nulling the shared slot would also destroy the host's own metadata.

Expected behavior

A metadata lookup for a type from a different load context should miss (falling back to the reflection path) rather than return metadata for an identically-named foreign type.

How to fix

IBindableType already carries its Type, so the lookup result can be validated in one comparison: reject a provider hit whose IBindableType.Type != originalType. PR to follow.

Environment

Uno.WinUI 6.7.16, Skia desktop; reproduced with a collectible-ALC-hosted app whose Uno.Extensions.Reactive.UI is loaded app-locally while the host also uses MVUX.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions