Skip to content

[Mono.Android] Default to SocketsHttpHandler in .NET 12 - #13013

Merged
simonrozsival merged 2 commits into
mainfrom
simonrozsival-sockets-handler-default
Oct 6, 2026
Merged

simonrozsival merged 2 commits into
mainfrom
simonrozsival-sockets-handler-default

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Use the shared System.Net.Http.SocketsHttpHandler implementation by default in .NET 12 instead of the Android-specific HTTP handler. This reduces reliance on a separate implementation with differing exception and cancellation behavior.

  • Default UseNativeHttpHandler to false, preserving explicit overrides.
  • Mark AndroidMessageHandler obsolete with a warning recommending SocketsHttpHandler; applications can still opt into the native handler.
  • Document the new default and deprecation, and suppress obsolete warnings in tests that intentionally exercise the legacy handler. No new unit test is included, as requested during review.
  • Update the two MAUI CoreCLR .apkdesc baselines using measured Release CI output, accepting the size increase without relaxing regression thresholds.

Accepted APK size increase

Switching to the sockets handler increases the measured MAUI CoreCLR APK size by 897,024 bytes (876 KiB) in both configurations. This is an intentional, accepted tradeoff for using the shared HTTP implementation.

MAUI CoreCLR configuration Previous APK size New APK size Increase Assembly-store increase
Without R8 18,434,956 bytes 19,331,980 bytes 897,024 bytes (4.87%) 903,264 bytes
With R8 16,092,044 bytes 16,989,068 bytes 897,024 bytes (5.57%) 902,144 bytes

The updated references exactly match the complete descriptors emitted by Release CI build 1624599, including the small accompanying native-library/DEX changes. Both simple-app CoreCLR size checks passed, so their references are unchanged. These are CI measurements, not locally generated measurements; local SDK preparation remains blocked as described below.

HTTP/3 is already disabled by default, and HTTP tracing, metrics, and EventSource support are already disabled in optimized builds as appropriate. The runtime switch audit did not identify an additional Android networking trimming switch to safely remove this increase. Disabling managed NTLM through _UseManagedNtlm=false does not gate Android's authentication implementation.

Related issues and PRs

These links provide implementation history and compatibility context; this PR does not claim to close them.

  • #5646 originally set UseNativeHttpHandler=true; this PR reverses that default for .NET 12.
  • #12934 documents remaining upload-exception differences between the native and sockets handlers.
  • #11682 and #11683 are earlier native-handler exception/cancellation alignment fixes.
  • dotnet/runtime#47083 introduced platform-specific handler selection and the feature switch.
  • dotnet/runtime#55384 added native underlying-handler support to HttpClientHandler, alongside SocketsHttpHandler.
  • dotnet/runtime#109532 tracks an Android sockets-handler client-certificate diagnostic limitation; retaining the explicit native-handler opt-in provides compatibility for affected applications.

Validation

  • Passed: dotnet msbuild src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets -nologo -p:AndroidApplication=true -p:AndroidMinimumSupportedApiLevel=24.0 -p:Configuration=<Debug|Release> -p:_AndroidRuntime=<CoreCLR|NativeAOT> [-p:UseNativeHttpHandler=<true|false>] -getProperty:UseNativeHttpHandler across all 12 configuration/runtime/unset-or-explicit-value combinations. Unset evaluates to false; explicit values are preserved.
  • Passed: git diff --check.
  • Passed: parsed both updated references as JSON and compared all 736 entries and package metadata in each against the complete descriptors emitted by Release CI build 1624599; both match exactly.
  • CI build 1624599: BuildReleaseArm64(False,CoreCLR,False) and BuildReleaseArm64(False,CoreCLR,True) passed. The two MAUI variants built successfully but failed against the previous size references; those references are now updated. Validation of the new baseline commit is pending CI.
  • Blocked: make prepare && make all failed during preparation/restore with NU1102: Microsoft.NETCore.App.Ref version 10.0.13 is unavailable from the configured feeds. make all did not run.
  • Blocked: make prepare CONFIGURATION=Release && make all CONFIGURATION=Release failed during preparation/restore for the same missing reference-pack version. The Release SDK build did not run.
  • Blocked: dotnet build src/Mono.Android/Mono.Android.csproj -v quiet failed during dependency restore for the same missing reference-pack version.
  • Local full-build and on-device tests were not run because SDK preparation/build is blocked.

Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

@wfurt fyi

Use the shared sockets HTTP implementation by default instead of the
Android-specific handler.  Preserve explicit UseNativeHttpHandler values
and mark AndroidMessageHandler obsolete with migration guidance.

Document the new default and suppress obsolete warnings in tests that
intentionally exercise the legacy handler.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 08:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The user-visible default change appears coherent, but compilation and on-device validation remain blocked by dependency restore failure.

Review effort: Balanced
Findings: None

What changed in this PR

Changes the .NET 12 Android HTTP default to SocketsHttpHandler while retaining explicit native-handler opt-in.

Changes:

  • Defaults UseNativeHttpHandler to false.
  • Marks AndroidMessageHandler obsolete and documents migration.
  • Suppresses expected obsolete warnings in legacy-handler tests.
File Description
Microsoft.Android.Sdk.DefaultProperties.targets Changes the default HTTP handler.
AndroidMessageHandler.cs Adds the obsolescence warning.
build-properties.md Documents the property and .NET 12 behavior.
AndroidMessageHandlerTests.cs Suppresses intentional obsolete usage.
AndroidMessageHandlerNegotiateAuthenticationTests.cs Suppresses intentional obsolete usage.
AndroidMessageHandlerIntegrationTests.cs Suppresses intentional obsolete usage.
AndroidMessageHandlerCancellationTests.cs Suppresses intentional obsolete usage.
AndroidMessageHandlerCancellationTests.Rewind.cs Suppresses intentional obsolete usage.

Accept the measured MAUI CoreCLR APK size increase from using the
sockets handler by default.  Refresh both R8 and non-R8 references from
Release CI build 1624599; keep the regression thresholds unchanged.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complete ten-file source/integration review supports the shared HTTP default while preserving explicit native-handler opt-in and warning-only obsolescence. Both full 736-entry references preserve schema/metadata/key sets and the existing comparator thresholds; the accepted 876 KiB increase and no-new-unit-test choice are not blockers. No blocking source issue remains. This is not a green-CI or measured-output certificate: current CI is still pending, and the canceled 1624599 descriptor-output equality claim was not independently verified.

@simonrozsival
simonrozsival enabled auto-merge (squash) October 6, 2026 12:05
@simonrozsival
simonrozsival merged commit 99dda3d into main Oct 6, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-sockets-handler-default branch October 6, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants