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.92k stars 2.24k forks source link

Unhelpful error messages (bad developer experience) #9256

Open KillyMXI opened 2 years ago

KillyMXI commented 2 years ago

Describe the bug

During the app development there were few occasions when Axaml editor reports "Invalid Markup" errors, but they are actually not about markup and absolutely unhelpful to identify the actual cause, resulting in frustrating debugging sessions.

To Reproduce Steps to reproduce the behavior:

  1. Work on a project (about 20 views) long enough, it will happen eventually.

I can't give more condensed steps exactly because I don't know yet where the issue is. That's exactly what I'm complaining about.

Expected behavior

Error message or Avalonia Diagnostics entry that will be more helpful to pinpoint what exactly is missing. Better way of reporting errors in code-behind is needed.

All I got is that the error happened when evaluating MainWindow.axaml. If it can't be linked to a certain line in the axaml file, the error message text should include more information. The evaluator code should customize error messages it rethrows to be more specific.

Screenshots

image

image

image

Desktop (please complete the following information):

timunie commented 2 years ago

Enable compiled Bindings if you have not already. Often these help to debug.

https://docs.avaloniaui.net/docs/data-binding/compiledbindings

kekekeks commented 2 years ago

https://github.com/AvaloniaUI/AvaloniaVS/blob/f18343c6fbe8fed90b8d3743b8c21483818f2eeb/AvaloniaVS.Shared/Services/PreviewerProcess.cs#L444 - we should probably somehow expose the stack trace here as well.

The problem is that exception happens when XAML is already parsed and compiled into MSIL. So there is no reliable way to extract the line info at that point.

kekekeks commented 2 years ago

We might need to add debug information support for System.Reflection.Emit backend as well - https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/a263ywy6(v=vs.100)?redirectedfrom=MSDN