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
24.69k stars 2.14k forks source link

catch compilers error "(Binding}" #13329

Open Belafon opened 9 months ago

Belafon commented 9 months ago

I spent almost an hour looking for the error in my xaml code until I found that the problem was only in one curly bracket. I had written "(" instead of "{", ItemsSource="(Binding Library.AllTypes}". The problem was that the compiler didn't find the error. It was an AutoCompleteBox which then recommended some selected letters).

The problem was really annoying, if only because both parentheses are almost unrecognizable when the text is zoomed out.

robloo commented 9 months ago

This is probably because the compiler can't tell that you don't intend for just a string input which is an array of chars.

Belafon commented 9 months ago

I do not see the background of that, but still I guess there has to be some pareser, that parses the array of chars and which can complain about wrong structure of it.

But I get that solving this problem is not very important.

maxkatz6 commented 9 months ago

"(Binding Library.AllTypes}" is a string. String is an array. Array is a valid value for ItemsSource.

At best, we can add a warning to help find these issues.

maxkatz6 commented 9 months ago

XAML warnings feature isn't yet implemented in XAMLX compiler, but I have working on it this month. I expect it to be available for 11.2 or 11.1.x builds, as I am focused on other issues for 11.1.

thevortexcloud commented 9 months ago

On a side note you can sometimes see XAML binding errors at runtme in the output. Since these are just regular exceptions you can also configure your IDE to break on them. Which often shows you the exact line the error is on. But I agree, tracking down XAML errors is a pain. Especially without an IDE.