Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldAccessException in KeyFrame Setter when propery is in an external F# assembly #7731

Open
marklam opened this issue Mar 1, 2022 · 0 comments

Comments

@marklam
Copy link

marklam commented Mar 1, 2022

Describe the bug
A control defined in an F# class library cannot be animated because a FieldAccessException is raised.

System.FieldAccessException
  HResult=0x80131507
  Message=Attempt by method 'AvaloniaApplication1.MainWindow.!XamlIlPopulate(System.IServiceProvider, AvaloniaApplication1.MainWindow)' to access field 'ControlLibraryFS.StringFormatFloatTextBlock.ValueProperty' failed.
  Source=AvaloniaApplication1
  StackTrace:
   at AvaloniaApplication1.MainWindow.!XamlIlPopulate(IServiceProvider , MainWindow ) in C:\temp\AvaloniaReflectionProb\AvaloniaApplication1\AvaloniaApplication1\MainWindow.axaml:line 15
   at AvaloniaApplication1.MainWindow.!XamlIlPopulateTrampoline(MainWindow )
   at AvaloniaApplication1.MainWindow.InitializeComponent() in C:\temp\AvaloniaReflectionProb\AvaloniaApplication1\AvaloniaApplication1\MainWindow.axaml.cs:line 19
   at AvaloniaApplication1.MainWindow..ctor() in C:\temp\AvaloniaReflectionProb\AvaloniaApplication1\AvaloniaApplication1\MainWindow.axaml.cs:line 11
   at AvaloniaApplication1.App.OnFrameworkInitializationCompleted() in C:\temp\AvaloniaReflectionProb\AvaloniaApplication1\AvaloniaApplication1\App.axaml.cs:line 18
   at Avalonia.Controls.AppBuilderBase`1.Setup() in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 313
   at Avalonia.Controls.AppBuilderBase`1.SetupWithLifetime(IApplicationLifetime lifetime) in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 180
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 208
   at AvaloniaApplication1.Program.Main(String[] args) in C:\temp\AvaloniaReflectionProb\AvaloniaApplication1\AvaloniaApplication1\Program.cs:line 14

The control works correctly without animation.

A similar control defined in a C# assembly can be animated.

Also if the F# control is defined in the same assembly as the Avalonia App, then the animation works (obviously this requires an F# Avalonia App project).

To Reproduce
There is a repo with a C# app and the C# and F# versions of the control here

Running the app with the xaml as-is will attempt to animate the C# and F# controls. Commenting-out the animation style for the control in the cf namespace shows that the F# control works ok otherwise, and the C# version can animate.

Expected behavior
The F# control to behave the same way as the C# control under the animation.

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 0.10.12

Additional context
Decompiling the F# assembly to C# in ILSpy shows that the main difference is that the property definitions are:

	public static readonly StyledProperty<string> StringFormatProperty;
	public static readonly StyledProperty<double> ValueProperty;

in C#, but in F# they are:

	internal static StyledProperty<string> StringFormatProperty;
	internal static StyledProperty<double> ValueProperty;

Presumably this is handled OK by the setter used for

    <cf:StringFormatFloatTextBlock Value=".98" StringFormat="{}{0:00.00%}" />

but not for

    <Style Selector="cf|StringFormatFloatTextBlock">
      <Style.Animations>
        <Animation Delay="0:0:2" Duration="0:0:30" IterationCount="1" FillMode="Both">
          <KeyFrame Cue="0%">
            <Setter Property="Value" Value ="0"/>
          </KeyFrame>
          <KeyFrame Cue="100%">
            <Setter Property="Value" Value ="1"/>
          </KeyFrame>
        </Animation>
      </Style.Animations>
    </Style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants