AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.07k stars 2.17k forks source link

Output better XAML errors #4466

Open grokys opened 4 years ago

grokys commented 4 years ago

Avalonia XAML error messages are sometimes less than ideal. This can be a big issue particularly for new users as the error messages tend to confuse more than help. Here's a few problems with them:

Some examples follow. This list isn't exhaustive but shows some of the more common errors:

Missing property

Invalid XAML

<Button Foo="Bar"/>

Avalonia

Unable to resolve suitable regular or attached property Foo on type Avalonia.Controls:Avalonia.Controls.Button (line 5 position 6) Line 5, position 6. [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]

WPF

The property 'Foo' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. Line 4 Position 13.

Evaluation

Better Error Message

Unable to resolve property 'Foo' on type 'Button'. Line 5, position 6.

Missing Event Handler

Invalid XAML:

<Button Click="Foo"/>

Avalonia:

Unable to find suitable setter or adder for property Click of type Avalonia.Controls:Avalonia.Controls.Button for argument netstandard:System.String, available setter parameter lists are: [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]
System.EventHandler`1<Avalonia.Interactivity.RoutedEventArgs> (line 5 position 13) Line 5, position 13. [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]

WPF:

'MainWindow' does not contain a definition for 'Foo' and no accessible extension method 'Foo' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?)

Evaluation

Better Error Message

Unable to find suitable handler for event 'Button.Click'. Valid handler signature is 'void Button_Click(object sender, RoutedEventArgs e)'.

Invalid value

Invalid XAML:

<Button HorizontalAlignment="Foo"/>

Avalonia:

Unable to find suitable setter or adder for property HorizontalAlignment of type Avalonia.Layout:Avalonia.Layout.Layoutable for argument netstandard:System.String, available setter parameter lists are: [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]
Avalonia.UnsetValueType [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]
Avalonia.Data.IBinding [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]
Avalonia.Layout.HorizontalAlignment (line 5 position 13) Line 5, position 13. [D:\projects\AvaloniaUI\Avalonia\samples\ControlCatalog\ControlCatalog.csproj]

WPF:

Requested value 'Foo' was not found.

Evaluation

Better Error Message

'Foo' is not a valid value for 'HorizontalAlignment'.

grokys commented 4 years ago

Another from gitter: https://gitter.im/AvaloniaUI/Avalonia?at=5f32b56eb103e45c830e2c2d

rstm-sf commented 3 years ago

Maybe add warning support as well? For example, Obsolete

maxkatz6 commented 4 months ago

"Unable to find the parent scope for AvaloniaProperty lookup" error can add a hint about where TemplateBinding can be used. And recommendation to use Bindings instead: https://github.com/AvaloniaUI/Avalonia/issues/15572

maxkatz6 commented 2 months ago

This too: https://github.com/AvaloniaUI/Avalonia/issues/16144

maxkatz6 commented 3 weeks ago

This too https://github.com/AvaloniaUI/Avalonia/discussions/16580#discussioncomment-10246589