AvaloniaVS icon indicating copy to clipboard operation
AvaloniaVS copied to clipboard

Event Generation in AvaloniaVS Causes Preview to Crash

Open kadir-ince opened this issue 8 months ago • 5 comments

Describe the bug

The preview crashes as soon as an event is generated. The preview only comes back to life after building the project. Until then, the preview remains in a crashed state.

https://github.com/AvaloniaUI/AvaloniaVS/assets/52853427/ef280573-7398-44c0-9c47-bf6811ded9be

To Reproduce

Open a AvaloniaUI project in Visual Studio. Use the Avalonia for Visual Studio extension to generate an event. Observe that the preview crashes immediately after the event is generated.

AvaloniaVS plugin version

11.4

Avalonia version

11.0.2

Visual Studio version

17.8.0 Preview 3.0

Relevant log output

09:10:01.497 [Information] 0 Starting previewer process for '"C:\Users\kince\Desktop\AvaloniaUI\AvaloniaApplication1\AvaloniaApplication1\bin\Debug\net7.0\AvaloniaApplication1.dll"'
09:10:01.513 [Information] 2960 Started previewer process for '"C:\Users\kince\Desktop\AvaloniaUI\AvaloniaApplication1\AvaloniaApplication1\bin\Debug\net7.0\AvaloniaApplication1.dll"'. Waiting for connection to be initialized.
09:10:01.664 [Information] 2960 Connection initialized
09:10:05.995 [Error] 2960 UpdateXamlResult error
System.Xaml.XamlException: ''/' is an unexpected token. The expected token is '='. Line 9, position 42.' Line number '9' and line position '42'.
09:10:06.539 [Error] 2960 UpdateXamlResult error
System.Xaml.XamlException: ''/' is an unexpected token. The expected token is '='. Line 9, position 42.' Line number '9' and line position '42'.
09:10:08.838 [Error] 2960 UpdateXamlResult error
System.Xaml.XamlException: 'Unable to find suitable setter or adder for property Click of type Avalonia.Controls:Avalonia.Controls.Button for argument System.Private.CoreLib:System.String, available setter parameter lists are:
System.EventHandler`1[[Avalonia.Interactivity.RoutedEventArgs, Avalonia.Base, Version=11.0.2.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]] Line 9, position 39.' Line number '9' and line position '39'.

Additional context

No response

kadir-ince avatar Oct 11 '23 06:10 kadir-ince

It is required to recompile C# project in order to see any changes in the previewer. Extension should disable the previewer until user completes his handler method and recompiles the project. With a hint message in the place of the previewer.

maxkatz6 avatar Oct 11 '23 09:10 maxkatz6

Alternatively, extension can force recompilation which isn't always a desired solution.

maxkatz6 avatar Oct 11 '23 09:10 maxkatz6

It is required to recompile C# project in order to see any changes in the previewer. Extension should disable the previewer until user completes his handler method and recompiles the project. With a hint message in the place of the previewer.

It works without recompilation in WPF. Do we have any options to make that work as it does in WPF?

Takoooooo avatar Oct 11 '23 10:10 Takoooooo

Do we have any options to make that work as it does in WPF

No. Well, we can inject an empty event handler into the assembly, but I feel like it will cause more conflicts between original and modified assemblies.

Keep in mind that WPF previewer didn't actually run the application, but only previewed the XAML.

maxkatz6 avatar Oct 12 '23 00:10 maxkatz6

However, it doesn't even fix even after I recompile the project.

The previewer says invalid markup and the error list says Unable to find suitable setter or adder for property Click of type Avalonia.Controls:Avalonia.Controls.Button for argument System.Private.CoreLib:System.String, available setter parameter lists are: System.EventHandler1[[Avalonia.Interactivity.RoutedEventArgs, Avalonia.Base, Version=11.0.2.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].

I swear that my function signature is correct and the code is able to run without exceptions. It works normally only after I restarted the whole VS.

HydrogenC avatar Mar 25 '24 02:03 HydrogenC