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

Output better XAML errors #4466

Open
grokys opened this issue Aug 9, 2020 · 6 comments
Open

Output better XAML errors #4466

grokys opened this issue Aug 9, 2020 · 6 comments
Labels
area-bindings area-xaml new-user-roadblock Issues likely to put off new users

Comments

@grokys
Copy link
Member

grokys commented Aug 9, 2020

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:

  • They duplicate the line/column numbers
  • They include the csproj which isn't (ever?) useful
  • The type information is noisy (always includes assembly and full namespace)
  • Types/members not quoted
  • They don't always give the correct column info (the open tag is marked as having the error when in reality the error occurs on e.g. a property)
  • The error message isn't always clear
  • They include irrelevant information
  • Setting value to a readonly property should show a better error TextBox throws exception if CanCopy / CanCut / CanPaste / CanRedo / CanUndo being modified #12218

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

  • Duplicate line/column numbers
  • csproj path is included
  • Types/members not quoted
  • This isn't attached property format so no need to mention "attached property"
  • Avalonia.Controls:Avalonia.Controls.Button is overkill: Button would suffice
  • The WPF error isn't much better to be honest

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

  • netstandard:System.String is overkill
  • System.EventHandler``1<Avalonia.Interactivity.RoutedEventArgs> isn't particularly useful for new users
  • Appears as two error messages
  • Says "property Click" but Click is an event
  • Again, WPF isn't much better though at least it's less verbose

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

  • Appears as three error messages
  • The info about UnsetValueType/IBinding isn't very useful as this obviously isn't a binding

Better Error Message

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

@grokys grokys added the new-user-roadblock Issues likely to put off new users label Aug 9, 2020
@grokys
Copy link
Member Author

grokys commented Aug 11, 2020

@rstm-sf
Copy link
Contributor

rstm-sf commented Apr 27, 2021

Maybe add warning support as well? For example, Obsolete

@maxkatz6
Copy link
Member

maxkatz6 commented May 1, 2024

"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:
#15572

@maxkatz6
Copy link
Member

This too: #16144

@maxkatz6
Copy link
Member

maxkatz6 commented Aug 5, 2024

This too #16580 (comment)

@maxkatz6
Copy link
Member

#17562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-bindings area-xaml new-user-roadblock Issues likely to put off new users
Projects
None yet
Development

No branches or pull requests

3 participants