Revert "[Android, iOS] Throw exceptions consistently for invalid StaticResource references to prevent relaunch crashes (#33859)"#35130
Merged
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35130Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35130" |
Contributor
There was a problem hiding this comment.
Pull request overview
Reverts the behavior introduced in #33859 on release/10.0.1xx-sr6, restoring prior handling for invalid {StaticResource ...} lookups to avoid production regressions.
Changes:
- Restore
{StaticResource}behavior to returnnull(after invokingResourceLoader.ExceptionHandler2) instead of always throwing. - Remove the ApplyPropertiesVisitor special-case that forced
StaticResourceExtensionto rethrow even when an exception handler is present. - Update/remove tests that were asserting the “always throw” behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/tests/Xaml.UnitTests/HotReloadStaticResourceException.xaml.cs | Updates the debug/hot reload unit test to validate handler invocation without expecting a thrown exception. |
| src/Controls/tests/DeviceTests/Xaml/StaticResourceTests.cs | Removes the device test that asserted missing StaticResource always throws with an exception handler present. |
| src/Controls/src/Xaml/MarkupExtensions/StaticResourceExtension.cs | Restores prior behavior: invoke ExceptionHandler2 (with file path) and return null; otherwise throw XamlParseException. |
| src/Controls/src/Xaml/ApplyPropertiesVisitor.cs | Removes the forced-rethrow path for StaticResourceExtension, returning to generic exception-handler behavior. |
Comments suppressed due to low confidence (1)
src/Controls/src/Xaml/ApplyPropertiesVisitor.cs:287
- In this catch block,
throw e;resets the exception stack trace to this location. With the StaticResourceExtension special-casing removed above, missing StaticResource exceptions will now typically be rethrown via this path (whenContext.ExceptionHandleris null), which makes diagnosing the original XAML failure harder. Please rethrow while preserving the original stack trace (e.g., use a barethrow;here).
{
if (Context.ExceptionHandler != null)
Context.ExceptionHandler(e);
else
throw e;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Reverts #33859 on the
release/10.0.1xx-sr6branch due to a regression.This change introduced consistent exception throwing for invalid StaticResource references, but it is causing regressions in production scenarios.