You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.field assembly static class [Avalonia.Base]Avalonia.StyledProperty`1<string> MessageProperty
If the controls project (.fsproj) has the property <ProduceReferenceAssembly>true</ProduceReferenceAssembly> then the view will be built against the controls' reference assembly, which will have had the property definition fields removed (because they were marked as internal).
Controls ProduceReferenceAssembly
View AvaloniaUseCompiledBindingsByDefault
Failure
false
false
Runtime System.FieldAccessException
false
true
Runtime System.FieldAccessException
true
false
Compiler Avalonia error AVLN3000: Unable to find suitable setter or adder for property Message of type FSharpControl:FSharpControl.UserControl1 for argument Avalonia.Markup:Avalonia.Data.Binding
true
true
Compiler Avalonia error AVLN3000: Unable to find suitable setter or adder for property Message of type FSharpControl:FSharpControl.UserControl1 for argument Avalonia.Markup:Avalonia.Data.Binding
The F# project also has a UserControl2 which defines a public static property-getter for the StyledProperty, which cannot be bound because it's defined as a property not a field.
Expected behavior
Since the compiled bindings will fail at runtime, the compiler should probably produce an error for an internal field being bound from a different assembly.
But most of all, it would be fantastic if the bindings could be made to a StyledProperty defined in a static property-getter, instead of only those defined in a static field, since F# can declare those easily. (See UserControl2.fs in the example repo.)
Avalonia version
11.1.3
OS
Windows
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
Avalonia bindings expect the properties of a control to be defined as static fields
e.g. C#
Which in the IL is
Static fields in F# are given
internal
/assembly
accesse.g. F#
Which in the IL is
If the controls project (.fsproj) has the property
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
then the view will be built against the controls' reference assembly, which will have had the property definition fields removed (because they were marked as internal).System.FieldAccessException
System.FieldAccessException
Avalonia error AVLN3000: Unable to find suitable setter or adder for property Message of type FSharpControl:FSharpControl.UserControl1 for argument Avalonia.Markup:Avalonia.Data.Binding
Avalonia error AVLN3000: Unable to find suitable setter or adder for property Message of type FSharpControl:FSharpControl.UserControl1 for argument Avalonia.Markup:Avalonia.Data.Binding
To Reproduce
https://github.com/marklam/AvaloniaBindToFSharpControl contains a C# view app with equivalent F# and C# control libraries, each containing a
UserControl1
with aMessage
Avalonia property.The F# project also has a
UserControl2
which defines a public static property-getter for theStyledProperty
, which cannot be bound because it's defined as a property not a field.Expected behavior
Since the compiled bindings will fail at runtime, the compiler should probably produce an error for an
internal
field being bound from a different assembly.But most of all, it would be fantastic if the bindings could be made to a
StyledProperty
defined in a static property-getter, instead of only those defined in a static field, since F# can declare those easily. (SeeUserControl2.fs
in the example repo.)Avalonia version
11.1.3
OS
Windows
Additional context
No response
The text was updated successfully, but these errors were encountered: