dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

Application not crashing if a resource string is incorrect in XAML #20018

Open asi-evin opened 10 months ago

asi-evin commented 10 months ago

Description

if there is an error with a resource string in XAML, the app will run fine while debugging. However, when you try to run the app without the debugger, it will crash.

Ideally, the application should not compile or at least crash in debug; it's VERY frusterating to try and find the error without the debugger.

https://github.com/dotnet/maui/assets/136844306/f60124f5-dfeb-4ed2-8e7c-9f199edbedca

I've noticed this issue on "StaticResource" strings, "Translation" strings and other custom Provider extension strings. There could be other XAML issues that compile and run successfully in debug, but it's difficult to ascertain.

This COULD be related to Hot Reload, I haven't tried without it. I also have only tested Android Emulator, Physcal Android Device, and Physical iOS Device (both remote and local).

Steps to Reproduce

  1. Create a new MAUI project

  2. Add a BackgroundColor to the button, or some other element using a Static Resource that does not exist (e.g. <Button BackgroundColor="{StaticResource blooper}"/><!-- static resource that does not exist -->)

  3. Run the Project in Debug

Expected Result: App should crash or not compile

Actual Result: App runs as if everything is hunky-dory

Further issues: App crashes when run without the debugger

Link to public reproduction project repository

No link required, can be replicated with a fresh project very easily.

Version with bug

8.0.6

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

Windows properly throws an exception during runtime, and will even tell you the position in xaml of the error. If possible, maintain windows as a viable platform, even if your app is mobile only.

Relevant log output

No response

mattleibow commented 10 months ago

Are there no warnings in the debug output window? I know we do log a lot. @StephaneDelcroix are we missing some logging for something? I am sure I have seen warings about invalid bindings and things.

asi-evin commented 10 months ago

@mattleibow I don't think it should matter. I'd hope if I accidentally typed a resource string wrong, I wouldn't need to slog through the output, especially since I may not know about the error for quite some time; I do a lot more debug runs than non-debug runs. But in the interest of clarity, below is the output with a local iOS device. I did a quick search for things such as "NonBlack" or "StaticResource" and didn't find anything.

ios log.txt

Edit: also did a search for "error" and "warning" and came up empty.

asi-evin commented 10 months ago

Got a chance to test with windows this morning, and it does properly throw an exception with a helpful message:

Position 33:17. StaticResource not found for key NonBlack

Still needs to be fixed for Android and iOS though (and presumably MacCatalyst). Difficult in my large project to do that, it's a mobile-only app, but I guess I have to get it running on windows now...

asi-evin commented 10 months ago

Just an FYI, I did have instances where windows did not crash or fail to compile when the debugger/hot reload was running. I couldn't re-create these behaviours in a small repro though.

I now have libraries that only work on the mobile platforms as well, so relying on windows to find XAML mistakes for me is simply no longer an option.

QianaJiao commented 8 months ago

Can repro this issue on the latest 17.10 preview 2 (8.0.14). Build and Debug can succeed without error, and starting without debug will crash.

asi-evin commented 2 months ago

Just hit this issue again last week where I had the following incorrect syntax on a xaml control:

VerticalOptions="{AppThemeBinding }"

Somehow in debug the code ran on both iOS and Android, but as soon as the debugger was detached, the app will crash on startup. No indication in debugger or build process that this is an issue. Tried with interpreter on AND off. The only way I found the exact location of the problem was I spent half a day "porting" the app to windows and in windows it not only crashed, but gave me the file, line, and position the error was on. Can we PLEASE have this on all platforms?

bmadtiger commented 1 month ago

Reproduced the same with MAUI.Controls 8.0.92 in VS17.11.5

A typo in the Binding correctly produce a compile-time error MainPage.xaml(18,17): XamlC error XFC0045: Binding: Property "Headliner" not found on "InvalidXAML.MainPage".

But a typo for a StaticResource does NOT produce a compile-time error and runs under the debugger with XAML Hot-reload enabled, ignoring the typo (so the style is not applied). Running the app without a debugger attached (or with XAML Hot-reload disabled) will crash trying to display the page.

Screenshot of app running with Debugger w/XAML Hot-reload enabled. Typo in style name is ignored, but without XAML Hot-reload it throws an exception that crashes the app