Open Numpsy opened 11 months ago
Hey @Numpsy 👋
Looks like the DynamicMemberAccess
attribute was completely missing for components.
https://github.com/fsprojects/Avalonia.FuncUI/commit/b0aa279c9760a2be2417230aad267a499bec2d47
Ok, will give it another go with that change later.
On a related note, the use of Linq.Expression at https://github.com/fsprojects/Avalonia.FuncUI/blob/b0aa279c9760a2be2417230aad267a499bec2d47/src/Avalonia.FuncUI/DataTemplateView.fs#L16C1-L16C1 seems to cause problems for the trimmer too (like, it can't see what the delegate given to DataTemplateView is doing and can trim out things that are used by it).
I'm not sure if that one can be fixed with a central annotation (A DynamicDependency
attribute at the call site can fix some of the issues), and that same pattern is used elsewhere in Avalonia libs, but for the record anyway
Hey @Numpsy 👋
Looks like the
DynamicMemberAccess
attribute was completely missing for components.
Actually, only just noticed, but the error in the callstack is
No parameterless constructor defined for type 'Avalonia.FuncUI.Component'
but it appears that in fact, Component doesn't have a parameterless constructor anyway?
Yup, Component constructor needs a render function.
But that makes it sound like something has gone awry and is trying to call the wrong constructor :-( This is where C# having a source based analyzer for this stuff where F# has to rely in the IL level one becomes a pain
Yeah.. that should never happen. If you can reproduce it let me know and I'll take a look
Something else must be getting removed when it shouldn't be I suppose.
fwiw, the two warnings about patcher.create
go away if ViewDelta is annotated:
type ViewDelta =
{ [<DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)>] ViewType: Type
Attrs: AttrDelta list
ConstructorArgs: obj array
KeyDidChange: bool
Outlet: (AvaloniaObject -> unit) voption }
but you then get
5>Avalonia.FuncUI.VirtualDom.Delta.ViewDelta.ViewDelta(Type,FSharpList`1<Delta.AttrDelta>,Object[],Boolean,FSharpValueOption`1<FSharpFunc`2<AvaloniaObject,Unit>>): value stored in field 'Avalonia.FuncUI.VirtualDom.Delta.ViewDelta.ViewType@' does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' requirements. The parameter 'viewType' of method 'Avalonia.FuncUI.VirtualDom.Delta.ViewDelta.ViewDelta(Type,FSharpList`1<Delta.AttrDelta>,Object[],Boolean,FSharpValueOption`1<FSharpFunc`2<AvaloniaObject,Unit>>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
from ViewDelta.From
because IView
isn't annoted, so it spirals off a bit into other things.
Yeah.. that should never happen. If you can reproduce it let me know and I'll take a look
I get a similar error with the ContactBook
sample project -
<PublishAot>true</PublishAot>
to the project fileand it crashes when run. It seems ok when building a single file / trimmed exe without AOT, and for comparison the counter test app seems fine as AOT so the base idea seems to work
The change in #399 appears to fix the crash I was seeing before in a NativeAOT build on my app, and also gets the ContactBook example further (it then falls over inside Bogus, but that's a different situation)
With the changes in #423 I have the control catalog running in NativeAOT in .NET 8.0 :-)
It does look like the drag and drop demo doesn't actually drag (on Windows at least), but that might be an issue with COM interop in Avalonia - needs an extra testing. Looking much better than it was before though :-)
This is a sort of followup to #281, but with a few FuncUI specific warnings in the build that might have local solutions, so -
I tried updating a FuncUI app to .NET 8 and publishing as NativeAOT with the RC2 SDK. There are alas loads of warnings from FSharp.Core that are outside our control, but also these ones from FuncUI:
and then this happens at runtime:
Which suggests that the existing
DynamicallyAccessedMembers
attributes aren't covering all required cases.Also, some of this might be hitting the existing TODO here about not using reflection: https://github.com/fsprojects/Avalonia.FuncUI/blob/a3b4b412752505124460a5f2f096dc37626da16c/src/Avalonia.FuncUI/VirtualDom/VirtualDom.Patcher.fs#L75