[trimmable-type-map] Avoid unused XML references - #12813
Draft
simonrozsival wants to merge 1 commit into
Draft
simonrozsival wants to merge 1 commit into
simonrozsival wants to merge 1 commit into
Conversation
Create XML marshalling metadata lazily so non-XML Export methods do not root System.Xml.ReaderWriter and System.Private.Xml. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Add coverage for XML parameter/return paths and all supported XML assembly identities.
Review effort: Lite
Findings: None
What changed in this PR
This PR lazily creates XML marshalling metadata to avoid unnecessary XML references in generated dispatch assemblies.
Changes:
- Defers XML metadata reference creation until needed.
- Preserves references for XML parser mappings.
- Adds conditional-reference regression tests.
| File | Summary |
|---|---|
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs |
Tests conditional XML reference emission. |
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ExportMethodDispatchEmitterContext.cs |
Adds lazy XML metadata reference getters. |
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ExportMethodDispatchEmitter.cs |
Uses lazy getters for XML marshalling emission. |
simonrozsival
marked this pull request as draft
September 17, 2026 06:54
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
[Export]dispatch assembliesSystem.Xml.ReaderWriterto a generated type-map assembly when exported signatures do not use XML parser mappingsXmlPullParserorXmlResourceParsermappings are usedAPK size and combined MAUI validation
The PR is draft because the stock MAUI
sample-contentapplication does not currently demonstrate an APK-size or packaged-assembly reduction from this change.The first stock .NET 11 Android CoreCLR Release comparison produced an identical signed APK before and after this change:
Three independent MAUI trimming fixes were then applied together:
ShadowTypeConverter's regex dependencyThe combined MAUI changes reduced the sample-content signed APK by 81,920 bytes, removed
XamlLoader,XamlParser, andLocalhostRegex, and reduced the retained XML/regex implementations. However,System.Xml.ReaderWriterremains rooted directly by source-generated XAML line-info calls in the application, andSystem.Private.Xmlremains transitively and through additional framework/control references.To exercise this PR's actual code path, the identical combined-MAUI input was then published twice with the trimmable Android type map explicitly enabled:
System.Xml.ReaderWriter.dllSystem.Private.Xml.dllAll 86 generated type-map DLLs were byte-identical, and none had a
System.Xml.ReaderWriterassembly reference. The sample-content app and its dependencies do not contain a non-XML[Export]dispatcher that triggers the bug fixed here. Its remainingSystem.Xml.ReaderWriterreference comes from generated XAMLInitializeComponentline-info services (System.Xml.IXmlLineInfo), outside the Android type-map generator.Therefore this change is valid generator cleanup and is covered by focused tests, but it does not currently reduce the stock MAUI sample-content APK or remove its XML assemblies. The benefit applies only to an app/library that generates a non-XML
[Export]dispatcher and has no independent XML roots.Tests
dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj --no-restore --nologo -v:minimalTypeMapAssemblyGeneratorTests.Generate_Export*coverage