Skip to content

chore: preserve properties on IListFeed<T> - #2990

Closed
jonpryor wants to merge 1 commit into
mainfrom
dev/jonpryor/jonp-preserve-IListFeed-T-Properties
Closed

jonpryor wants to merge 1 commit into
mainfrom
dev/jonpryor/jonp-preserve-IListFeed-T-Properties

Conversation

@jonpryor

@jonpryor jonpryor commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

It's our favorite exercise, making uno.chefs run under NativeAOT!

dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop -bl \
  Chefs/Chefs.csproj \
  -p:SelfContained=true -p:PublishAot=true -p:IsAotCompatible=true -p:UseSkiaRendering=true \
  -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
  -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen
Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs

Login to the app, click on a recipe, and no Ingredients are shown.

The app log contains messages such as:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient]

The problem is that the properties on Ingredient are not being
preserved.

The question: how "best" to preserve them?

As @jonpryor is the "automagic" sort, the "obvious" (and possibly
incorrect) answer is "something outside of uno.chefs should ensure
that the properties are preserved".

But where is Ingredient mentioned within uno.chefs? What types
can be (ab)used to preserve properties?

Turns out, not too many places:

% git grep '\<Ingredient\>'
Chefs/Business/Models/Ingredient.cs:public record Ingredient
Chefs/Business/Models/Ingredient.cs:    public Ingredient(IngredientData ingredientData)
Chefs/Business/Services/Recipes/IRecipeService.cs:      ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct);
Chefs/Business/Services/Recipes/RecipeService.cs:       public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct)
Chefs/Business/Services/Recipes/RecipeService.cs:               return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty;
Chefs/Presentation/RecipeDetailsModel.cs:       public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct));

The Ingredient type definition won't help, IImmutableList<T>
would be a massive stretch (plus we don't own it), which brings us
to IListFeed<T>: that is a type that we control!

Update IListFeed<T> to preserve properties on T:

partial interface IListFeed<
  [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
> {}

Perhaps unsurprisingly, that change impacts everything.
(The patch size escalated quickly.)

Integrating this change back into uno.chefs, and now I'm able to see
Ingredients, without other changes to uno.chefs! (At least it worked.)

But! We next see this message in the app log:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]]

Similar question as before: how do we preserve the properties on
BindableListFeed<T>?

Raising the question: where is BindableListFeed<T> coming from?

This was quite interesting, as BindableListFeed<T> doesn't appear
anywhere in uno.chefs!

% git grep BindableListFeed
# no source code matches
% grep -ril BindableListFeed _gen
# no matches

Add some printf logging to the BindableListFeed<T> constructors to
see how it's constructed, and:

   at Uno.Extensions.Reactive.Bindings.BindableListFeed`1..ctor(String, IListState`1) + 0x91
   at Uno.Extensions.Reactive.Bindings.BindableFactory.CreateList[T](String, IListState`1) + 0x2d
   at Chefs.Presentation.RecipeDetailsViewModel..ctor(RecipeDetailsModel) + 0x333
   at Chefs.Presentation.RecipeDetailsViewModel..ctor(Recipe recipe, INavigator navigator, IRecipeService recipeService, IUserService userService, IMessenger messenger, IShareService shareService) + 0xa0

BindableListFeed<Ingredient> is constructed via a
BindableFactory.CreateList(…) invocation within the generated
RecipeDetailsViewModel constructor.

Slight problem: there is no BindableFactory.CreateList(…) invocation
within the RecipeDetailsViewModel constructor!

public partial class RecipeDetailsViewModel {
  protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
  {
    // …
    if (Ingredients is null)
    {
      var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
      var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
      Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
    }
    // …
  }
}

However, BindableHelper.CreateBindableList(…) does call
BindableFactory.CreateList(…), so this is presumably a case of
method inlining by NativeAOT.

With that in mind, @jonpryor can think of three ways to cause the
BindableListFeed<Ingredient> properties to be preserved:

  1. Some form of change within FeedsGenerator, or
  2. Update BindableFactory.CreateList<T>() to use
    [DynamicDependency] to preserve the properties, or
  3. Update the BindableListFeed<T> constructors to have
    [DynamicDependency].

The advantages to (3) is that it works, it's straightforward, and
annotation site is "close" to the site of intended effect.
(BindableFactory.CreateList<T>() doesn't obviously scream out
"I may require dynamic dependencies!" The constructor doesn't either,
but at least it's on the type being impacted!)

(3) also gives us an interesting "hammer" with which to solve related
issues. Issues such as:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView]

@jonpryor has no idea where BasicView is constructed from, but if
it's constructed, we probably need its properties, so: add
[DynamicDependency] to the BasicView constructor! The message
is fixed. (This is a fascinating hammer, ripe for abuse.)

GitHub Issue (If applicable): closes #

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Wasm UI Tests are not showing unexpected any differences. Validate PR Screenshots Compare Test Run results.
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

Internal Issue (If applicable):

@jonpryor
jonpryor requested a review from dr1rrb December 19, 2025 13:59
@jonpryor
jonpryor force-pushed the dev/jonpryor/jonp-preserve-IListFeed-T-Properties branch from 941db81 to 64ad608 Compare December 19, 2025 15:55
@jonpryor
jonpryor marked this pull request as ready for review December 19, 2025 18:17

@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.

We should have attributes only for classes that are in the Presentation namespace, we should not add that attribute everywhere.

If we need this, I would assume it means that we need to generate the attributes in the generated code, but not on all interfaces.

internal class ListStateImpl<T> : FeedToListFeedAdapter<T>, IListState<T>, IStateImpl
internal class ListStateImpl<
[DynamicallyAccessedMembers(ListFeed.TRequirements)]
T

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.

There is no reason why we need this on the ListStateImpl : it's a backing state for the IListState, not necessarily bound to the UI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See also, but the reason this was changed was because if IListFeed<T> changes, then this also needs to change. Most of this PR, as architected, is "fallout" of adding annotations to IListFeed<T>. The only way to not have this change is by not changing IListFeed<T> (which I suspect is your actual thinking).

Comment on lines 333 to 383
@@ -340,12 +343,18 @@ public IListState<T> GetOrCreateListState<T>(IListFeed<T> feed)
/// <param name="feed">The list feed to get source from.</param>
/// <returns>The list state wrapping the given list feed</returns>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public IListState<T> GetOrCreateListState<T>(IFeed<IImmutableList<T>> feed)
public IListState<T> GetOrCreateListState<
[DynamicallyAccessedMembers(ListFeed.TRequirements)]
T
>(IFeed<IImmutableList<T>> feed)
=> States.GetOrCreateState<IFeed<IImmutableList<T>>, IListState<T>>(feed, static (ctx, f) => new ListStateImpl<T>((StateImpl<IImmutableList<T>>)ctx.GetOrCreateState(f)));

// WARNING: DO NOT USE, this breaks the cache by providing a custom config!
// We need to make those config "upgradable" in order to properly share the instances of State
internal ListStateImpl<T> DoNotUse_GetOrCreateListState<T>(IListFeed<T> feed, StateUpdateKind updatesKind)
internal ListStateImpl<T> DoNotUse_GetOrCreateListState<
[DynamicallyAccessedMembers(ListFeed.TRequirements)]
T
>(IListFeed<T> feed, StateUpdateKind updatesKind)
=> States.GetOrCreateState(feed, /*static*/ (ctx, f) => new ListStateImpl<T>(new StateImpl<IImmutableList<T>>(ctx, f.AsFeed(), updatesKind: updatesKind)));

/// <summary>
@@ -367,7 +376,10 @@ public IState<T> CreateState<T>(Option<T> initialValue)
/// <returns>The list state wrapping the given list feed</returns>
/// <exception cref="ObjectDisposedException">This context has been disposed.</exception>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public IListState<T> CreateListState<T>(Option<IImmutableList<T>> initialValue)
public IListState<T> CreateListState<
[DynamicallyAccessedMembers(ListFeed.TRequirements)]
T
>(Option<IImmutableList<T>> initialValue)
=> States.CreateState<IImmutableList<T>, IListState<T>>(initialValue, static (ctx, iv) => new ListStateImpl<T>((StateImpl<IImmutableList<T>>)ctx.CreateState(iv)));

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.

Same here: Those methods are not related to the UI and does not use reflection internally, we should not need any attributes in that class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See also, but the reason this was changed was because if IListFeed<T> changes, then this also needs to change. Most of this PR, as architected, is "fallout" of adding annotations to IListFeed<T>. The only way to not have this change is by not changing IListFeed<T> (which I suspect is your actual thinking).

Related question: what use case is there to use IListFeed<T> et al in a non UI context? Would it make sense to use IListFeed<T> in e.g. a non-UI daemon process?

@jonpryor
jonpryor force-pushed the dev/jonpryor/jonp-preserve-IListFeed-T-Properties branch from 64ad608 to 6778137 Compare December 19, 2025 19:39
It's our favorite exercise, making uno.chefs run under NativeAOT!

	dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop -bl \
	  Chefs/Chefs.csproj \
	  -p:SelfContained=true -p:PublishAot=true -p:IsAotCompatible=true -p:UseSkiaRendering=true \
	  -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
	  -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen
	Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs

Login to the app, click on a recipe, and no Ingredients are shown.

The app log contains messages such as:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient]

The problem is that the properties on `Ingredient` are not being
preserved.

The question: how "best" to preserve them?

As @jonpryor is the "automagic" sort, the "obvious" (and possibly
incorrect) answer is "something *outside* of uno.chefs should ensure
that the properties are preserved".

But where is `Ingredient` mentioned within uno.chefs?  What types
can be (ab)used to preserve properties?

Turns out, not too many places:

	% git grep '\<Ingredient\>'
	Chefs/Business/Models/Ingredient.cs:public record Ingredient
	Chefs/Business/Models/Ingredient.cs:    public Ingredient(IngredientData ingredientData)
	Chefs/Business/Services/Recipes/IRecipeService.cs:      ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct);
	Chefs/Business/Services/Recipes/RecipeService.cs:       public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct)
	Chefs/Business/Services/Recipes/RecipeService.cs:               return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty;
	Chefs/Presentation/RecipeDetailsModel.cs:       public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct));

The `Ingredient` type definition won't help, `IImmutableList<T>`
would be a *massive* stretch (plus we don't own it), which brings us
to `IListFeed<T>`: that *is* a type that we control!

Update `IListFeed<T>` to preserve properties on `T`:

	partial interface IListFeed<
	  [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
	> {}

Perhaps unsurprisingly, that change impacts *everything*.
(The patch size escalated quickly.)

Integrating this change back into uno.chefs, and now I'm able to see
Ingredients, without other changes to uno.chefs!  (At least it worked.)

But!  We next see this message in the app log:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]]

Similar question as before: how do we preserve the properties on
`BindableListFeed<T>`?

Raising the question: where is `BindableListFeed<T>` coming from?

This was *quite* interesting, as `BindableListFeed<T>` doesn't appear
*anywhere* in uno.chefs!

	% git grep BindableListFeed
	# no source code matches
	% grep -ril BindableListFeed _gen
	# no matches

Add some printf logging to the `BindableListFeed<T>` constructors to
see how it's constructed, and:

	   at Uno.Extensions.Reactive.Bindings.BindableListFeed`1..ctor(String, IListState`1) + 0x91
	   at Uno.Extensions.Reactive.Bindings.BindableFactory.CreateList[T](String, IListState`1) + 0x2d
	   at Chefs.Presentation.RecipeDetailsViewModel..ctor(RecipeDetailsModel) + 0x333
	   at Chefs.Presentation.RecipeDetailsViewModel..ctor(Recipe recipe, INavigator navigator, IRecipeService recipeService, IUserService userService, IMessenger messenger, IShareService shareService) + 0xa0

`BindableListFeed<Ingredient>` is constructed via a
`BindableFactory.CreateList(…)` invocation within the generated
`RecipeDetailsViewModel` constructor.

Slight problem: there is no `BindableFactory.CreateList(…)` invocation
within the `RecipeDetailsViewModel` constructor!

	public partial class RecipeDetailsViewModel {
	  protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
	  {
	    // …
	    if (Ingredients is null)
	    {
	      var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
	      var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
	      Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
	    }
	    // …
	  }
	}

However, `BindableHelper.CreateBindableList(…)` *does* call
`BindableFactory.CreateList(…)`, so this is presumably a case of
method inlining by NativeAOT.

With that in mind, @jonpryor can think of three ways to cause the
`BindableListFeed<Ingredient>` properties to be preserved:

 1. Some form of change within FeedsGenerator, or
 2. Update `BindableFactory.CreateList<T>()` to use
    `[DynamicDependency]` to preserve the properties, or
 3. Update the `BindableListFeed<T>` constructors to have
    `[DynamicDependency]`.

The advantages to (3) is that it works, it's straightforward, and
annotation site is "close" to the site of intended effect.
(`BindableFactory.CreateList<T>()` doesn't obviously scream out
"I may require dynamic dependencies!"  The constructor doesn't either,
but at least it's on the type being impacted!)

(3) also gives us an interesting "hammer" with which to solve related
issues.  Issues such as:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView]

@jonpryor has no idea where `BasicView` is constructed from, but if
it's constructed, we *probably* need its properties, so: add
`[DynamicDependency]` to the `BasicView` constructor!  The message
is fixed.  (This is a fascinating hammer, ripe for abuse.)
@jonpryor
jonpryor force-pushed the dev/jonpryor/jonp-preserve-IListFeed-T-Properties branch from 6778137 to 832766a Compare December 19, 2025 19:52
@jonpryor

Copy link
Copy Markdown
Contributor Author

@dr1rrb wrote:

We should have attributes only for classes that are in the Presentation namespace, we should not add that attribute everywhere.

If we need this, I would assume it means that we need to generate the attributes in the generated code, but not on all interfaces.

I don't disagree, but I don't know what the alternative looks like or would be architected.

Background?

Consider this snippet from the original description:

But where is Ingredient mentioned within uno.chefs? What types can be (ab)used to preserve properties?

Turns out, not too many places:

% git grep '\<Ingredient\>'
Chefs/Business/Models/Ingredient.cs:public record Ingredient
Chefs/Business/Models/Ingredient.cs:    public Ingredient(IngredientData ingredientData)
Chefs/Business/Services/Recipes/IRecipeService.cs:      ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct);
Chefs/Business/Services/Recipes/RecipeService.cs:       public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct)
Chefs/Business/Services/Recipes/RecipeService.cs:               return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty;
Chefs/Presentation/RecipeDetailsModel.cs:       public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct));

Not mentioned in the original description, but still of potential interest: where is Ingredient mentioned in the generated code?

% grep -ri '\<Ingredient\>' _gen
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:		public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; }

(As per the original description, _gen is $(CompilerGeneratedFilesOutputPath), and contains the generated files.)

Here are the full contents of Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs. In closer non-sh context, use of Ingredient is:

// Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs
namespace Chefs.Presentation
{
	public partial class RecipeDetailsViewModel
	{
		protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
		{
			// …
			if (Ingredients is null)
			{
				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
				var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
				Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
			}
			// …
		}

		protected virtual void __Reactive_BindableInitializeForUpdatedModel(object updatedModel, global::Uno.Extensions.Reactive.Core.SourceContext ctx)
		{
			// …
			if (Ingredients is null)
			{
				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
				var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
				Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
			}
			// …
		}

		public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; }
	}
}

It's basically still restricted to IListFeed<T>

Alternate solutions

I can think of two alternative solutions to abusing IListFeed<T> to preserve the properties on T:

  1. Leave it to the customer
  2. FeedsGenerator change to emit [DynamicDependency]
  3. XamlGenerator change?

Leave it to the customer

nothing automagic; if things break, then the customer needs to fix it.

In this case, the properties on Ingredient can be preserved with:

diff --git a/Chefs/Business/Models/Ingredient.cs b/Chefs/Business/Models/Ingredient.cs
index 5b2fe9e3..000e8aaf 100644
--- a/Chefs/Business/Models/Ingredient.cs
+++ b/Chefs/Business/Models/Ingredient.cs
@@ -1,8 +1,10 @@
+using System.Diagnostics.CodeAnalysis;
 using IngredientData = Chefs.Client.Models.IngredientData;
 namespace Chefs.Business.Models;
 
 public record Ingredient
 {
+	[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Ingredient))]
 	public Ingredient(IngredientData ingredientData)
 	{
 		UrlIcon = ingredientData.UrlIcon;

This fixes the original mentioned message:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient]

but there are others, which aren't fixed:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Category] property getter does not exist on type [Chefs.Business.Models.CategoryWithCount]

Just apply the same solution!

diff --git a/Chefs/Business/Models/CategoryWithCount.cs b/Chefs/Business/Models/CategoryWithCount.cs
index 856dbf2f..c66e0755 100644
--- a/Chefs/Business/Models/CategoryWithCount.cs
+++ b/Chefs/Business/Models/CategoryWithCount.cs
@@ -2,6 +2,7 @@ namespace Chefs.Business.Models;
 
 public record CategoryWithCount
 {
+	[System.Diagnostics.CodeAnalysis.DynamicDependency(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties, typeof(CategoryWithCount))]
 	internal CategoryWithCount(int count, Category category)
 	{
 		Count = count;

Then there's the other messages mentioned in the original description:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]]

Just apply the same solution…?

diff --git a/Chefs/Business/Models/Ingredient.cs b/Chefs/Business/Models/Ingredient.cs
index 5b2fe9e3..ee4e868a 100644
--- a/Chefs/Business/Models/Ingredient.cs
+++ b/Chefs/Business/Models/Ingredient.cs
@@ -1,8 +1,11 @@
+using System.Diagnostics.CodeAnalysis;
 using IngredientData = Chefs.Client.Models.IngredientData;
 namespace Chefs.Business.Models;
 
 public record Ingredient
 {
+	[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Ingredient))]
+	[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Uno.Extensions.Reactive.Bindings.BindableListFeed<>))]
 	public Ingredient(IngredientData ingredientData)
 	{
 		UrlIcon = ingredientData.UrlIcon;

This is starting to get bananas, but it works…

But then there's:

fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView]

Minor problem: BasicView is internal, so Chefs can't mention it. I also don't (yet) know how BasicView is instantiated, so I don't currently know what logical callers could use [DynamicDependency]. (And that's assuming you'd even agree to [DynamicDependency] to preserve properties on BasicView, as it's not in a "Presentation" namespace…)

The fundamental problem here is that "nobody" is going to add [DynamicDependncy] to their models like this. It's not an existing code pattern

FeedsGenerator change

I haven't prototyped this, so I have no idea how straightforward of complicated it would be, but one can imagine that FeedsGenerator would emit [DynamicDependency] on any type that is mentioned within the constructor:

// Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs
namespace Chefs.Presentation
{
	public partial class RecipeDetailsViewModel
	{
		[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Ingredient))]
		[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Step))]
		[DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(global::Chefs.Business.Models.Review))]
		protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
		{
			// …
		}
	}
}

This will help with Ingredient et al, but won't immediately help with BindableListFeed<T>. That could also be mentioned as above, but the relation between RecipeDetailsViewModel and BindableListFeed<T> is not at all obvious.

This won't help at all with BasicView (it's internal!).

I can imagine this partially working, but I'm not sure what a "proper" fix for BindableListFeed<T> and BasicView looks like if not "slap [DynamicDependency(.Properties, typeof(DeclType))] on both BindableListFeed<T> and BasicView (as currently done in this PR).

XamlGenerator change?

This is the most far-out idea, and I have no idea if it's possible, much less how practical it is.

My (years old) original "understanding" of XAML is that it was a "serialization format" that could 1:1 become an object graph.

RecipeDetailsPage.xaml has:

<utu:AutoLayout …>
  <TextBlock Text="{Binding Ingredients.Count, Converter={StaticResource StringFormatter}, ConverterParameter='{}{0} items'" />
</utu:AutoLayout>

would be converted into:

new Uno.Toolkit.UI.AutoLayout {
    new TextBlock {
        Text = …,
    }
}

except (1) that's not at all how it works, and (2) my understanding doesn't take bindings/etc. into consideration. The actual TextBlock.Text setup is this monstrosity:

// _gen/Uno.UI.SourceGenerators/Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator/RecipeDetailsPage_ccf3346ad2a15b56e6347d9f3770ace0.cs
__p1.SetBinding(
	global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty,
	new Microsoft.UI.Xaml.Data.Binding()
	{
		Path = @"Ingredients.Count",
		Converter = (global::Microsoft.UI.Xaml.Data.IValueConverter)global::Uno.UI.ResourceResolverSingleton.Instance.ResolveResourceStatic("StringFormatter", typeof(global::Microsoft.UI.Xaml.Data.IValueConverter), context: global::Chefs.GlobalStaticResources.__ParseContext_),
		ConverterParameter = @"{0} items",
	}
);

Notably absent: any static, C#, reference to Ingredients.Count. It's all in strings, ultimately via Reflection. (Which is why we're in this mess in the first place!)

If there were some way to have XamlGenerator statically reference the actually used properties, then we wouldn't need [DynamicallyAccessedMembers]/[DynamicDependency] in the first place!

However, this would be a massive change, and I cannot currently conceive of what that would even look like.

jonpryor added a commit that referenced this pull request Dec 22, 2025
Context: #2990
Context: #2990 (review)
Context: #2969
Context: 8870ddf

It's our favorite exercise, making uno.chefs run under NativeAOT!

	dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop -bl \
	  Chefs/Chefs.csproj \
	  -p:SelfContained=true -p:PublishAot=true -p:IsAotCompatible=true -p:UseSkiaRendering=true \
	  -p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
	  -p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen
	Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs

Login to the app, click on a recipe, and no Ingredients are shown.

The app log contains messages such as:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Name] property getter does not exist on type [Chefs.Business.Models.Ingredient]

The problem is that the properties on `Ingredient` are not being
preserved.

The question: how "best" to preserve them?

As @jonpryor is the "automagic" sort, the "obvious" (and possibly
incorrect) answer is "something *outside* of uno.chefs should ensure
that the properties are preserved".

But where is `Ingredient` mentioned within uno.chefs?  What types
can be (ab)used to preserve properties?

Turns out, not too many places:

	% git grep '\<Ingredient\>'
	Chefs/Business/Models/Ingredient.cs:public record Ingredient
	Chefs/Business/Models/Ingredient.cs:    public Ingredient(IngredientData ingredientData)
	Chefs/Business/Services/Recipes/IRecipeService.cs:      ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct);
	Chefs/Business/Services/Recipes/RecipeService.cs:       public async ValueTask<IImmutableList<Ingredient>> GetIngredients(Guid recipeId, CancellationToken ct)
	Chefs/Business/Services/Recipes/RecipeService.cs:               return ingredientsData?.Select(x => new Ingredient(x)).ToImmutableList() ?? ImmutableList<Ingredient>.Empty;
	Chefs/Presentation/RecipeDetailsModel.cs:       public IListFeed<Ingredient> Ingredients => ListFeed.Async(async ct => await _recipeService.GetIngredients(Recipe.Id, ct));

The `Ingredient` type definition won't help, `IImmutableList<T>`
would be a *massive* stretch (plus we don't own it), which brings us
to `IListFeed<T>`: that *is* a type that we control!

PR #2990 explored an approach of updating `IListFeed<T>` to preserve
properties on `T`:

	partial interface IListFeed<
	  [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
	> {}

This approach was deemed far-reaching and undesirable.

What else can be used to preserve `Ingredient` properties?
Let's look at the *generated* code:

	% grep -ri '\<Ingredient\>' _gen
	_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
	_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:				var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
	_gen/Uno.Extensions.Reactive.Generator/Uno.Extensions.Reactive.Generator.FeedsGenerator/Chefs.Presentation.RecipeDetailsModel.Bindable.g.cs:		public global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient> Ingredients { get; private set; }

The last line -- the `Ingredients` property -- is similar to
PR #2969/8870ddf4.  We could do something similar for `IListFeed<T>`
usage, and generate:

	namespace Chefs.Presentation;
	public partial class RecipeDetailsViewModel
	{
	  public Uno.Extensions.Reactive.IListFeed<Chefs.Business.Models.Ingredient> Ingredients
	  {
	    [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Chefs.Business.Models.Ingredient))]
	    get;
	    private set;
	  }
	}

The use of `[DynamicDependency]` ensures that the public properties
on `Ingredient` can still be accessed via Reflection, *without*
needing to modify `IListFeed<T>`itself.

Integrating this change back into uno.chefs, and now I'm able to see
Ingredients, without other changes to uno.chefs!

But!  We next see this message in the app log:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.BindableListFeed`1[Chefs.Business.Models.Ingredient]]

Similar question as before: how do we preserve the properties on
`BindableListFeed<T>`?

Raising the question: where is `BindableListFeed<T>` coming from?

This was *quite* interesting, as `BindableListFeed<T>` doesn't appear
*anywhere* in uno.chefs!

	% git grep BindableListFeed
	# no source code matches
	% grep -ril BindableListFeed _gen
	# no matches

Add some printf logging to the `BindableListFeed<T>` constructors to
see how it's constructed, and:

	   at Uno.Extensions.Reactive.Bindings.BindableListFeed`1..ctor(String, IListState`1) + 0x91
	   at Uno.Extensions.Reactive.Bindings.BindableFactory.CreateList[T](String, IListState`1) + 0x2d
	   at Chefs.Presentation.RecipeDetailsViewModel..ctor(RecipeDetailsModel) + 0x333
	   at Chefs.Presentation.RecipeDetailsViewModel..ctor(Recipe recipe, INavigator navigator, IRecipeService recipeService, IUserService userService, IMessenger messenger, IShareService shareService) + 0xa0

`BindableListFeed<Ingredient>` is constructed via a
`BindableFactory.CreateList(…)` invocation within the generated
`RecipeDetailsViewModel` constructor.

Slight problem: *there is no* `BindableFactory.CreateList(…)`
invocation within the `RecipeDetailsViewModel` constructor!

	public partial class RecipeDetailsViewModel {
	  protected RecipeDetailsViewModel(global::Chefs.Presentation.RecipeDetailsModel model)
	  {
	    // …
	    if (Ingredients is null)
	    {
	      var ingredientsSource = (global::Uno.Extensions.Reactive.IListFeed<global::Chefs.Business.Models.Ingredient>) model.Ingredients ?? throw new NullReferenceException("The list feed property 'Ingredients' is null. Public feeds properties must be initialized in the constructor.");
	      var ingredientsSourceListState = ctx.GetOrCreateListState(ingredientsSource);
	      Ingredients = global::Uno.Extensions.Reactive.Bindings.BindableHelper.CreateBindableList(nameof(Ingredients), ingredientsSourceListState);
	    }
	    // …
	  }
	}

However, `BindableHelper.CreateBindableList(…)` *does* call
`BindableFactory.CreateList(…)`, so this is presumably a case of
method inlining by NativeAOT.

With that in mind, @jonpryor can think of three ways to cause the
`BindableListFeed<Ingredient>` properties to be preserved:

 1. Some form of change within FeedsGenerator, or
 2. Update `BindableFactory.CreateList<T>()` to use
    `[DynamicDependency]` to preserve the properties, or
 3. Update the `BindableListFeed<T>` constructors to have
    `[DynamicDependency]`.

The problem with (1) is that it associates types which perhaps
shouldn't be associated "like that", e.g.

	namespace Chefs.Presentation;
	public partial class RecipeDetailsViewModel
	{
	  public Uno.Extensions.Reactive.IListFeed<Chefs.Business.Models.Ingredient> Ingredients
	  {
	    [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Chefs.Business.Models.Ingredient))]
	    [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(Uno.Extensions.Reactive.Bindings.BindableListFeed<>))]
	    get;
	    private set;
	  }
	}

Why should `IListFeed<Ingredient>` use dictate referencing of
`BindableListFeed<T>`?

(2) is reasonable.

The advantages to (3) is that it works, it's straightforward, and
annotation site is "close" to the site of intended effect.
(`BindableFactory.CreateList<T>()` doesn't obviously scream out
"I may require dynamic dependencies!"  The constructor doesn't either,
but at least it's on the type being impacted!)

(3) also gives us an interesting "hammer" with which to solve related
issues.  Issues such as:

	fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
	      The [Count] property getter does not exist on type [Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView]

`BasicView` in turn is constructed via:

	   at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Views.BasicView..ctor(CollectionFacet, CollectionChangedFacet, BindableCollectionExtendedProperties, SelectionFacet, PaginationFacet, EditionFacet) + 0x4f
	   at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.LeafStrategy.CreateView(IBindableCollectionViewSource) + 0x1d4
	   at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.DataLayer..ctor(DataLayer, IServiceProvider, IBindableCollectionDataLayerStrategy, IDispatcher) + 0x71
	   at Uno.Extensions.Reactive.Bindings.Collections._BindableCollection.Data.DataLayer.Create(IBindableCollectionDataLayerStrategy, IObservableCollection, IServiceProvider, IDispatcher) + 0x3e
	   at Uno.Extensions.Reactive.Dispatching.DispatcherLocal`1.GetValueCore(IDispatcher, IDispatcher) + 0x285
	   at Uno.Extensions.Reactive.Dispatching.DispatcherLocal`1.GetValue(IDispatcher) + 0x3f
	   at Uno.Extensions.Reactive.Bindings.BindableListFeed`1.<Uno-Extensions-Reactive-ISignal<Uno-Extensions-Reactive-IMessage>-GetSource>d__66.MoveNext() + 0xb1
	   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine&) + 0x4d
	   at Uno.Extensions.Reactive.Bindings.BindableListFeed`1.<Uno-Extensions-Reactive-ISignal<Uno-Extensions-Reactive-IMessage>-GetSource>d__66.System.Collections.Generic.IAsyncEnumerator<Uno.Extensions.Reactive.IMessage>.MoveNextAsync() + 0x46
	   at Uno.Extensions.Reactive.Utils.FeedUIHelper.<MoveNext>d__4`1.MoveNext() + 0x115
	   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine&) + 0x4d
	   at Uno.Extensions.Reactive.Utils.FeedUIHelper.MoveNext[T](IAsyncEnumerator`1, CancellationToken) + 0x82
	   at Uno.Extensions.Reactive.Utils.FeedUIHelper.<GetSource>d__0.MoveNext() + 0x227
	   at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object) + 0x89
	   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread) + 0x57
	   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, Boolean) + 0x52
	   at System.Threading.Tasks.Task.RunContinuations(Object) + 0x4f
	   at System.Threading.Tasks.Task`1.TrySetResult(TResult) + 0x8e
	   at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1.SetResult(TResult) + 0x29
	   at Uno.Extensions.Reactive.Utils.FeedUIHelper.<GetSourceEnumerator>d__3`1.MoveNext() + 0x284
	   at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object) + 0x89

i.e. "nowhere" near `*.Presentation` logic, and yet its properties
are used by XAML.

Regardless, if it's constructed, we *probably* need its properties, so:
add `[DynamicDependency]` to the `BasicView` constructor!  The message
is fixed.  (This is a fascinating hammer, ripe for abuse.)
@jonpryor
jonpryor marked this pull request as draft December 22, 2025 20:21
@jonpryor

Copy link
Copy Markdown
Contributor Author

PR #2994 updates src/Uno.Extensions.Reactive.Generator to cause the Ingredient properties to preserved. This is likely the more reasonable approach.

@jonpryor

jonpryor commented Jan 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by PR #2994.

@jonpryor jonpryor closed this Jan 5, 2026
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