Event Generation in AvaloniaVS Causes Preview to Crash
kadir-ince opened this issue · 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.
Recording.2023-10-11.090303.mp4
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
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.
Alternatively, extension can force recompilation which isn't always a desired solution.
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?
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.
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.