Commit e4157bf
committed
chore: Preserve ModelAttribute.Bindable constructors, properties
Context: unoplatform/uno.chefs#1709
While running the uno.chefs app on macOS 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:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen
Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs
(along with a change from unoplatform/uno.chefs#1709 to `Program.cs`
to call `App.InitializeLogging()`…)
Console output would contain the following warnings:
fail: Uno.UI.Dispatching.NativeDispatcher[0]
NativeDispatcher unhandled exception
System.InvalidOperationException: A suitable constructor for type 'Chefs.Presentation.ShellViewModel' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
This is actually fixable within uno.extensions! The `ShellViewModel`
type is referenced by *both* `[Model]` and `IModel<ShelViewModel>`
in generated code:
// Chefs.Presentation.ShellModel.g.cs
namespace Chefs.Presentation;
[Model(typeof(ShellViewModel))]
partial record ShellModel : IModel<ShellViewModel> {
}
`ModelAttribute` and `IModel<TViewModel>` thus give us places to tell
NativeAOT to preserve the constructors on `ShellViewModel`.
After having done so, the new failure message appears:
fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
The [Pages] property getter does not exist on type [Chefs.Presentation.WelcomeViewModel]
This can *also* be fixed by telling NativeAOT to preserve
*properties* as well, as `WelcomeViewModel` goes through similar
infrastructure as `ShellViewModel`.
Update `ModelAttribute` so that the `Type bindable` constructor
parameter preserves both constructors and properties.
Update `IModel<TViewModel>` *for consistency* with `[Model]` to also
preserve constructor and properties on type parameter `TViewModel`.
TODO: this fixes `ShellViewModel` and similar constructs, but next
we have:
fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
The [CurrentIndex] property getter does not exist on type [Chefs.Business.Models.BindableIntIteratorViewModel]
There are no `[Model]` or `IModel<TViewModel>` uses which mention
`BindableIntIteratorViewModel`, so the current fix doesn't help.
Investigate what needs to be done to fix `BindableIntIteratorViewModel`.1 parent 2af4d6b commit e4157bf
2 files changed
Lines changed: 14 additions & 2 deletions
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
25 | 34 | | |
26 | 35 | | |
27 | 36 | | |
| |||
0 commit comments