Fix: Throw a clear error when an SVG lacks dimensions instead of a NullReferenceException#33194
Conversation
|
Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #32460 by replacing a confusing NullReferenceException with a clear InvalidOperationException when SVG files lack proper dimensions. The fix adds validation in the DrawUnscaled method to detect when an SVG has empty dimensions and provides an actionable error message to help developers fix their SVG files.
Key Changes
- Added size validation check before creating SKImageInfo to prevent NullReferenceException
- Throws InvalidOperationException with descriptive message when SVG dimensions are empty
- Provides guidance about missing width/height or viewBox attributes in the error message
| if (size.IsEmpty) | ||
| { | ||
| throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size and may be missing width/height or viewBox attributes."); | ||
| } |
There was a problem hiding this comment.
The error check only occurs in the scale < 1 branch (downscaling), but the same NullReferenceException can occur in the scale >= 1 branch at line 41 when DrawPicture is called with an empty SVG. The constructor already logs a warning at line 29-30 when this condition is detected, but the error should be thrown earlier or consistently in all code paths to prevent confusing failures. Consider moving this validation to the constructor where it's already being detected, or add the same check in the scale >= 1 branch.
| var size = GetOriginalSize(); | ||
| if (size.IsEmpty) | ||
| { | ||
| throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size and may be missing width/height or viewBox attributes."); |
There was a problem hiding this comment.
The error message says "may be missing width/height or viewBox attributes" but according to the PR description, the actual issue is specifically when SVG files have width/height attributes but lack a viewBox attribute. The message should be more precise about what's actually required, for example: "The SVG has no size. Ensure the SVG includes a viewBox attribute or both width and height attributes with valid dimensions."
| throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size and may be missing width/height or viewBox attributes."); | |
| throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size. Ensure the SVG includes a viewBox attribute or both width and height attributes with valid dimensions."); |
🤖 AI Summary📊 Expand Full Review🔍 Pre-Flight — Context & Validation📝 Review Session — I modified the fix ·
|
| File:Line | Reviewer Says | Status |
|---|---|---|
| SkiaSharpSvgTools.cs:50 (old) | Error check only in scale < 1 branch, not scale >= 1 FIXED in d5f2afd | |
| SkiaSharpSvgTools.cs:49 (old) | Error message should be more precise FIXED in d5f2afd |
Issue Discussion Edge Cases
- SetTrend (issue author): Suggested using
x,y,width,heightattributes ifviewBoxisn't provided, sinceviewBoxis optional per SVG spec. Current error message accommodates this: "viewBox attribute or both width and height attributes with valid dimensions."
Test Status
No automated tests can be added (documented by PR author and confirmed by prior agent review):
- Bug only manifests on Android/iOS where SkiaSharp returns empty dimensions for SVGs without viewBox
unit tests always pass regardless of fix
device tests are not applicable
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #33194 | Add size.IsEmpty check at TOP of DrawUnscaled, throw InvalidOperationException with clear PENDING (Gate) |
SkiaSharpSvgTools.cs (+5/-3) |
Protects BOTH scale improved since prior review | paths message |
🚦 Gate — Test Verification
📝 Review Session — I modified the fix · d5f2afd
** NO TESTS AVAILABLEResult:**
Platform: N/A (Build-time error, platform-specific behavior)
Mode: N/A
Test Status
No automated tests exist and cannot be added for this PR.
Per the PR author:
"Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built."
This was confirmed by the prior agent review (December 19, 2025) and verified by inspection of SkiaSharpSvgToolsTests.cs.
Why Tests Cannot Be Added
- Platform-specific SkiaSharp behavior: The bug only manifests on Android/iOS where SkiaSharp returns empty dimensions for SVGs without
viewBox. macOS SkiaSharp always returns non-empty dimensions. - Build-time error: This is a Resizetizer error during project compilation, before any app is deployed. Device tests are not applicable.
- Testing environment limitation: Unit tests run on macOS where the SkiaSharp behavior doesn't reproduce the bug.
Decision: Proceed to Code Review
Gate cannot be validated through automated tests. This is a legitimate platform limitation (not an environment blocker). The fix quality is assessed through code review and manual testing documented by the PR author.
Proceeding to Fix analysis and Report phases per autonomous execution policy.
🔧 Fix — Analysis & Comparison
📝 Review Session — I modified the fix · d5f2afd
Fix Exploration Status
** Cannot validate fixesSKIPPED Status:**
Reason for Skipping
The try-fix skill requires tests that:
- FAIL without the fix
- PASS with the fix
For this PR, that is impossible because:
- Unit tests run on macOS where SkiaSharp never returns empty dimensions
- Tests pass both with and without the fix on macOS (the CI/testing environment)
- The bug only reproduces on Android/iOS at build-time (Resizetizer), not at test-time
Running try-fix would produce meaningless results: any change that compiles would appear to "pass" the tests regardless of correctness. This is the same platform limitation that prevented Gate from running.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #33194 | Add check at top of , throw | Code Review PASSED | SkiaSharpSvgTools.cs (+5/-3) |
Protects both scale paths, implements prior review feedback |
Exhausted: N/ try-fix cannot be run meaningfully for this build-time/platform-specific bugA
Selected Fix: PR's code review confirms it correctly addresses the issueimplementation
📋 Report — Final Recommendation
📝 Review Session — I modified the fix · d5f2afd
Final Recommendation: APPROVE
Summary
PR #33194 fixes a build-time NullReferenceException in Resizetizer's SVG-to-PNG conversion that occurs when SVG files define width/height attributes but lack a viewBox attribute (Android/iOS platforms only). The fix adds validation at the top of DrawUnscaled to detect empty SVG dimensions and throw a clear, actionable InvalidOperationException.
The PR author has fully implemented the recommendations from a prior agent review (Dec 19, 2025), which requested changes specifically because the validation only protected the downscaling path. The current code now protects both scale paths.
Root Cause
SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) on Android/iOS when loading SVG files without a viewBox attribute. The code then attempted to:
NullReferenceException
NullReferenceException
Neither path had size validation before the fix.
Fix Analysis
Code change (5 lines added, 3 removed):
public override void DrawUnscaled(SKCanvas canvas, float scale)
{
var size = GetOriginalSize();
if (size.IsEmpty) // NEW: validates BEFORE any drawing
{
throw new InvalidOperationException($"Cannot draw SVG file '{Filename}'. The SVG has no size. Ensure the SVG includes a viewBox attribute or both width and height attributes with valid dimensions.");
}
if (scale >= 1)
{
canvas.DrawPicture(svg.Picture, Paint); // NOW PROTECTED
}
else
{
var info = new SKImageInfo((int)size.Width, (int)size.Height); // NOW PROTECTED Why this is the correct fix:
- Fail-fast at the right level of abstraction
- Error message includes filename, root cause, and solution
InvalidOperationExceptionis semantically correct- Consolidates the
GetOriginalSize()call (was duplicated before) - Zero regression silent path unchanged on macOS/Windows where SkiaSharp never returns empty dimensionsrisk
Gate Status
NO TESTS Legitimate platform limitation:AVAILABLE** **
- Bug only manifests on Android/iOS where SkiaSharp returns empty dimensions for SVGs without viewBox
unit tests pass both with/without fix
device tests not applicable - Manual validation by PR author on all 4 platforms (Android, iOS, Windows, Mac)
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #33194 | guard at top of , throw | Code Review PASSED | SkiaSharpSvgTools.cs (+5/-3) |
Both scale paths protected |
Exhausted: N/ try-fix cannot be meaningfully run (tests pass both with/without fix on macOS)A
Selected Fix: PR's implementation
PR Title & Description
Title no change requiredAccurate :
** One stale note needs removal:Description:**
The "Note:" paragraph at the end of "Description of Change" says validation only protects the downscaling this was the bug identified in the prior review and has since been fixed. Remove this paragraph.path
Comparison to Prior Review
| Aspect | Prior Review (Dec 19, 2025) | Current (Feb 17, 2026) |
|---|---|---|
| Critical issue ( 1 Not fixed FIXED | unprotected) | |
| Code Duplicate GetOriginalSize Single call | () | structure |
| REQUEST CHANGES APPROVE | Recommendation |
Required Action Before Merge
Remove the outdated "Note:" paragraph from the PR description's "Description of Change" section. Everything else is accurate.
📋 Expand PR Finalization Review
Title: ✅ Good
Current: Fix: Throw a clear error when an SVG lacks dimensions instead of a NullReferenceException
Description: ✅ Good
Description needs updates. See details below.
✨ Suggested PR Description
[!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!
Issue Details
NullReferenceException occurred when building MAUI apps with SVG files that lack a viewBox attribute. The error occurred during the Resizetizer's SVG-to-PNG conversion process and did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix.
Root Cause
SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading SVG files without a viewBox attribute. The code then attempted to create an SKImageInfo with zero dimensions, causing SKSurface.Create(info) to return null. Accessing surface.Canvas on that null reference produced the NullReferenceException.
Description of Change
Added validation at the top of DrawUnscaled to check size.IsEmpty before attempting to draw the SVG. When an empty size is detected, an InvalidOperationException is thrown with a clear, actionable message. By placing the check before the if (scale >= 1) branch, both the upscaling and downscaling code paths are protected.
Key change in SkiaSharpSvgTools.cs:
GetOriginalSize()is now called at the start ofDrawUnscaled- Throws
InvalidOperationExceptionwith a clear message if the SVG has empty dimensions - Both
scale >= 1(vector draw) andscale < 1(raster downscale) paths are guarded
Test Case
Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions.
The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox.
Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built.
Platforms Tested
- Android
- iOS
- Windows
- Mac
Issues Fixed
Fixes #32460
Code Review: ✅ Passed
Code Review — PR #33194
File: src/SingleProject/Resizetizer/src/SkiaSharpSvgTools.cs
Critical Issues
None.
Looks Good
Fix is correct and complete.
The IsEmpty check is placed at the very beginning of DrawUnscaled, before both the scale >= 1 (vector draw) and scale < 1 (raster downscale) branches. Both code paths are protected from the NullReferenceException caused by zero-dimension SVGs.
Error message is accurate and actionable:
"Cannot draw SVG file '{Filename}'. The SVG has no size. Ensure the SVG includes a viewBox attribute or both width and height attributes with valid dimensions."
This matches the reviewer's suggestion and is an improvement over the previous version ("may be missing width/height or viewBox attributes").
Variable reuse is clean: size is now computed once at the top of the method and reused in the else branch, eliminating the previous duplication.
Suggestions (minor, non-blocking)
Stale log message wording in constructor (lines 29-30):
if (pic.CullRect.Size.IsEmpty)
Logger?.Log($"SVG picture did not have a size and will fail to generate. ({Filename})");Now that DrawUnscaled throws a clear InvalidOperationException, the phrase "will fail to generate" is slightly misleading — the build will now fail with a clear, actionable error rather than a cryptic NullReferenceException. This is a minor wording opportunity only, not a correctness issue.
Suggested wording: "SVG picture has no size and will throw an error during generation. ({Filename})"
Summary
| Category | Finding |
|---|---|
| Fix correctness | Both scale paths protected — correct |
| Error message | Accurate and actionable |
| Code cleanliness | Variable reuse, removed duplication |
| Constructor log | Minor wording opportunity (not a bug) |
…llReferenceException (#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
…llReferenceException (#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
…llReferenceException (#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
…llReferenceException (#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
…llReferenceException (dotnet#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes dotnet#32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
…llReferenceException (#33194) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue. ### Root Cause SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw. ### Description of Change Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files. **Note:** The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #32460 ### Test case Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions. The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox. Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/ed1b413d-1a21-45a8-8f08-e45a1254f11f" >| <video src="https://github.com/user-attachments/assets/3c4ada96-b1f8-4880-83e5-581684de71c4">|
## What's Coming .NET MAUI inflight/candidate introduces significant improvements across all platforms with focus on quality, performance, and developer experience. This release includes 46 commits with various improvements, bug fixes, and enhancements. ## Button - [Android] Implemented material3 support for Button by @Dhivya-SF4094 in #33173 <details> <summary>🔧 Fixes</summary> - [Implement Material3 support for Button](#33172) </details> ## CollectionView - [Android] Fix RemainingItemsThresholdReachedCommand not firing when CollectionView has Header and Footer both defined by @SuthiYuvaraj in #29618 <details> <summary>🔧 Fixes</summary> - [Android : RemainingItemsThresholdReachedCommand not firing when CollectionVew has Header and Footer both defined](#29588) </details> - [iOS/MacCatalyst] Fix CollectionView ScrollTo for horizontal layouts by @Shalini-Ashokan in #33853 <details> <summary>🔧 Fixes</summary> - [[iOS/MacCatalyst] CollectionView ScrollTo does not work with horizontal Layout](#33852) </details> - [iOS & Mac] Fixed IndicatorView Size doesnt update dynamically by @SubhikshaSf4851 in #31129 <details> <summary>🔧 Fixes</summary> - [[iOS, Catalyst] IndicatorView.IndicatorSize does not update dynamically at runtime](#31064) </details> - [Android] Fix for CollectionView Scrolled event is triggered on the initial app load. by @BagavathiPerumal in #33558 <details> <summary>🔧 Fixes</summary> - [[Android] CollectionView Scrolled event is triggered on the initial app load.](#33333) </details> - [iOS, Android] Fix for CollectionView IsEnabled=false allows touch interactions by @praveenkumarkarunanithi in #31403 <details> <summary>🔧 Fixes</summary> - [More issues with CollectionView IsEnabled, InputTransparent, Opacity via Styles and code behind](#19771) </details> - [iOS] Fix VerticalOffset Update When Modifying CollectionView.ItemsSource While Scrolled by @devanathan-vaithiyanathan in #34153 <details> <summary>🔧 Fixes</summary> - [[iOS]VerticalOffset Not Reset to Zero After Clearing ItemSource in CollectionView](#26798) </details> ## DateTimePicker - [Android] Fix DatePicker MinimumDate/MaximumDate not updating dynamically by @HarishwaranVijayakumar in #33687 <details> <summary>🔧 Fixes</summary> - [[regression/8.0.3] [Android] DatePicker control minimum date issue](#19256) - [[Android] DatePicker does not update MinimumDate / MaximumDate in the Popup when set in the viewmodel after first opening](#33583) </details> ## Drawing - Android drawable perf by @albyrock87 in #31567 ## Editor - [Android] Implemented material3 support for Editor by @SyedAbdulAzeemSF4852 in #33478 <details> <summary>🔧 Fixes</summary> - [Implement Material3 Support for Editor](#33476) </details> ## Entry - [iOS, Mac] Fix for CursorPosition not updating when typing into Entry control by @SyedAbdulAzeemSF4852 in #30505 <details> <summary>🔧 Fixes</summary> - [Entry control CursorPosition does not update on TextChanged event [iOS Maui 8.0.7] ](#20911) - [CursorPosition not calculated correctly on behaviors events for iOS devices](#32483) </details> ## Flyoutpage - [Android, Windows] Fix for FlyoutPage toolbar button not updating on orientation change by @praveenkumarkarunanithi in #31962 <details> <summary>🔧 Fixes</summary> - [Flyout page in Android does not show flyout button (burger) consistently](#24468) </details> - Fix for First Item in CollectionView Overlaps in FlyoutPage.Flyout on iOS by @praveenkumarkarunanithi in #29265 <details> <summary>🔧 Fixes</summary> - [[iOS] CollectionView not rendering first item correctly in FlyoutPage.Flyout](#29170) </details> ## Image - [Android] Fix excessive memory usage for stream and resource-based image loading by @Shalini-Ashokan in #33590 <details> <summary>🔧 Fixes</summary> - [[Android] Unexpected high Bitmap.ByteCount when loading image via ImageSource.FromResource() or ImageSource.FromStream() in .NET MAUI](#33239) </details> - [Android] Fix for Resize method returns an image that has already been disposed by @SyedAbdulAzeemSF4852 in #29964 <details> <summary>🔧 Fixes</summary> - [In GraphicsView, the Resize method returns an image that has already been disposed](#29961) - [IIMage.Resize bugged behaviour](#31103) </details> ## Label - Fixed Label Span font property inheritance when applied via Style by @SubhikshaSf4851 in #34110 <details> <summary>🔧 Fixes</summary> - [`Span` does not inherit text styling from `Label` if that styling is applied using `Style` ](#21326) </details> - [Android] Implemented material3 support for Label by @SyedAbdulAzeemSF4852 in #33599 <details> <summary>🔧 Fixes</summary> - [Implement Material3 Support for Label](#33598) </details> ## Map - [Android] Fix Circle Stroke color is incorrectly updated as Fill color. by @NirmalKumarYuvaraj in #33643 <details> <summary>🔧 Fixes</summary> - [[Android] Circle Stroke color is incorrectly updated as Fill color.](#33642) </details> ## Mediapicker - [iOS] Fix: invoke MediaPicker completion handler after DismissViewController by @yuriikyry4enko in #34250 <details> <summary>🔧 Fixes</summary> - [[iOS] Media Picker UIImagePickerController closing issue](#21996) </details> ## Navigation - Fix ContentPage memory leak on Android when using NavigationPage modally (fixes #33918) by @brunck in #34117 <details> <summary>🔧 Fixes</summary> - [[Android] Modal TabbedPage whose tabs are NavigationPage(ContentPage) is retained after PopModalAsync()](#33918) </details> ## Picker - [Android] Implement material3 support for TimePicker by @HarishwaranVijayakumar in #33646 <details> <summary>🔧 Fixes</summary> - [Implement Material3 support for TimePicker](#33645) </details> - [Android] Implemented Material3 support for Picker by @SyedAbdulAzeemSF4852 in #33668 <details> <summary>🔧 Fixes</summary> - [Implement Material3 support for Picker](#33665) </details> ## RadioButton - [Android] Implemented material3 support for RadioButton by @SyedAbdulAzeemSF4852 in #33468 <details> <summary>🔧 Fixes</summary> - [Implement Material3 Support for RadioButton](#33467) </details> ## Setup - Clarify MA003 error message by @jeremy-visionaid in #34067 <details> <summary>🔧 Fixes</summary> - [MA003 false positive with 9.0.21](#26599) </details> ## Shell - [Android] Fix TabBar FlowDirection not updating dynamically by @SubhikshaSf4851 in #33091 <details> <summary>🔧 Fixes</summary> - [[Android, iOS] FlowDirection RTL is not updated dynamically on Shell TabBar](#32993) </details> - [Android] Fix page not disposed on Shell replace navigation by @Vignesh-SF3580 in #33426 <details> <summary>🔧 Fixes</summary> - [[Android] [Shell] replace navigation leaks current page](#25134) </details> - [Android] Fixed Shell flyout does not disable scrolling when FlyoutVerticalScrollMode is set to Disabled by @NanthiniMahalingam in #32734 <details> <summary>🔧 Fixes</summary> - [[Android] Shell.FlyoutVerticalScrollMode="Disabled" does not disable scrolling](#32477) </details> ## Single Project - Fix: Throw a clear error when an SVG lacks dimensions instead of a NullReferenceException by @Shalini-Ashokan in #33194 <details> <summary>🔧 Fixes</summary> - [MAUI Fails To Convert Valid SVG Files Into PNG Files (Object reference not set to an instance of an object)](#32460) </details> ## SwipeView - [iOS] Fix SwipeView stays open on iOS after updating content by @devanathan-vaithiyanathan in #31248 <details> <summary>🔧 Fixes</summary> - [[iOS] - Swipeview with collectionview issue](#19541) </details> ## TabbedPage - [Windows] Fixed IsEnabled Property not works on Tabs by @NirmalKumarYuvaraj in #26728 <details> <summary>🔧 Fixes</summary> - [ShellContent IsEnabledProperty does not work](#5161) - [[Windows] Shell Tab IsEnabled Not Working](#32996) </details> - [Android] Fix NavigationBar overlapping StatusBar when NavigationBar visibility changes by @Vignesh-SF3580 in #33359 <details> <summary>🔧 Fixes</summary> - [[Android] NavigationBar overlaps with StatusBar when mixing HasNavigationBar=true/false in TabbedPage on Android 15 (API 35)](#33340) </details> ## Templates - Fix for unable to open task using keyboard navigation on windows platform by @SuthiYuvaraj in #33647 <details> <summary>🔧 Fixes</summary> - [Unable to open task using keyboard: A11y_.NET maui_User can get all the insights of Dashboard_Keyboard](#30787) </details> ## TitleView - Fix for NavigationPage.TitleView does not expand with host window in iPadOS 26+ by @SuthiYuvaraj in #33088 ## Toolbar - [iOS] Fix toolbar items ignoring BarTextColor on iOS/MacCatalyst 26+ by @Shalini-Ashokan in #34036 <details> <summary>🔧 Fixes</summary> - [[iOS 26] ToolbarItem color with custom BarTextColor not working](#33970) </details> - [Android] Fix for ToolbarItem retaining the icon from the previous page on Android when using NavigationPage. by @BagavathiPerumal in #32311 <details> <summary>🔧 Fixes</summary> - [Toolbaritem keeps the icon of the previous page on Android, using NavigationPage (not shell)](#31727) </details> ## WebView - [Android] Fix WebView in a grid expands beyond it's cell by @devanathan-vaithiyanathan in #32145 <details> <summary>🔧 Fixes</summary> - [Android - WebView in a grid expands beyond it's cell](#32030) </details> ## Xaml - ContentPresenter: Propagate binding context to children with explicit TemplateBinding by @HarishwaranVijayakumar in #30880 <details> <summary>🔧 Fixes</summary> - [Binding context in ContentPresenter](#23797) </details> <details> <summary>🔧 Infrastructure (1)</summary> - [Revert] ContentPresenter: Propagate binding context to children with explicit TemplateBinding by @Ahamed-Ali in #34332 </details> <details> <summary>🧪 Testing (6)</summary> - [Testing] Feature Matrix UITest Cases for Shell Flyout Page by @NafeelaNazhir in #32525 - [Testing] Feature Matrix UITest Cases for Brushes by @LogishaSelvarajSF4525 in #31833 - [Testing] Feature Matrix UITest Cases for BindableLayout by @LogishaSelvarajSF4525 in #33108 - [Android] Add UI tests for Material 3 CheckBox by @HarishwaranVijayakumar in #34126 <details> <summary>🔧 Fixes</summary> - [[Android] Add UI tests for Material 3 CheckBox](#34125) </details> - [Testing] Feature Matrix UITest Cases for Shell Tabbed Page by @NafeelaNazhir in #33159 - [Testing] Fixed Test case failure in PR 34294 - [03/2/2026] Candidate - 1 by @TamilarasanSF4853 in #34334 </details> <details> <summary>📦 Other (2)</summary> - Bumps Syncfusion.Maui.Toolkit dependency to version 1.0.9 by @PaulAndersonS in #34178 - Fix crash when closing Windows based app when using TitleBar by @MFinkBK in #34032 <details> <summary>🔧 Fixes</summary> - [Unhandled exception "Value does not fall within the expected range" when closing Windows app](#32194) </details> </details> **Full Changelog**: main...inflight/candidate
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!
Issue Details
NullReferenceException occurred when building MAUI apps with SVG files that define width and height attributes but lack a viewBox attribute. The error occurred during the Resizetizer’s SVG-to-PNG conversion process. The exception did not clearly indicate what was wrong with the SVG files, making it difficult to diagnose and fix the issue.
Root Cause
SkiaSharp's SVG parser returns a Picture with empty dimensions (Width=0, Height=0) when loading certain SVG files without a viewBox attribute. The code attempted to create an SKImageInfo with these zero dimensions, causing a NullReferenceException when trying to draw.
Description of Change
Added validation in DrawUnscaled method to check if size.IsEmpty before attempting to draw the SVG. When detected, throws InvalidOperationException with a clear message. This provides actionable guidance to users to add the missing viewBox attribute to their SVG files.
Note: The validation currently only protects the downscaling path (scale < 1). The upscaling path (scale >= 1) should also be protected by moving the check earlier in the method.
Validated the behavior in the following platforms
Issues Fixed
Fixes #32460
Test case
Not able to add a unit test for this scenario, as it passes both with and without the fix because macOS SkiaSharp never returns empty dimensions.
The fix only triggers on Android/iOS, where SkiaSharp returns an empty size for SVGs without a viewBox.
Device tests are not applicable because this is a build-time Resizetizer error that occurs before the app is built.
Output ScreenShot
BeforeFix.mov
AfterFix.mov