Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

AndroidHttpClientHandlerType and XA_HTTP_CLIENT_HANDLER_TYPE rely on runtime type resolution via Type.GetType(), which is incompatible with trimming and NativeAOT. This PR disables this feature by default and adds deprecation warnings.

Changes

Runtime

  • Add XaHttpClientHandlerType feature switch to RuntimeFeature.cs (disabled by default)
  • When disabled, GetHttpMessageHandler() returns AndroidMessageHandler directly—no reflection
  • Legacy behavior preserved when switch is enabled via _AndroidUseXaHttpClientHandlerType

Build-time validation

  • XA1042 (error): NativeAOT + AndroidHttpClientHandlerType set → build fails
  • XA1043 (warning): MonoVM/CoreCLR + AndroidHttpClientHandlerType set → deprecation warning
  • XA1044 (warning): XA_HTTP_CLIENT_HANDLER_TYPE found in @(AndroidEnvironment) files

Property defaults

  • Removed default value for $(AndroidHttpClientHandlerType) in DefaultProperties.targets

Migration

Pass custom handlers via constructor instead of MSBuild property:

var client = new HttpClient(new MyCustomHandler());

Documentation

Added docs for XA1042, XA1043, XA1044.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Trimming] Put code for resolving HttpMessageHandler type name behind feature switch</issue_title>
<issue_description>### Android framework version

net11.0-android (Preview)

Affected platform version

.NET 11

Description

We support passing the HTTP message handler type name via the AndroidHttpClientHandlerType or the XA_HTTP_CLIENT_HANDLER_TYPE environment variable. This is not compatible with trimming by default and while we can make sure this type is preserved by ILLink via custom trimmer steps, there is no reasonable way to do this for NativeAOT.

I suggest disabling the handler type lookup via XA_HTTP_CLIENT_HANDLER_TYPE env variable by default and introducing a feature switch to re-enable this feature. The GetHttpMessageHandler() method would simply return an instance of AndroidMessageHandler by default.

Steps to Reproduce

  1. Set AndroidHttpClientHandlerType to an assembly qualified type name
  2. This should not take precedence over UseNativeHttpHandler

Did you find any workaround?

No response

Relevant log output

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 29, 2026 11:21
… variable by default

- Add XaHttpClientHandlerType feature switch to RuntimeFeature.cs (disabled by default)
- Update GetHttpMessageHandler() to return AndroidMessageHandler directly when feature disabled
- Add ILLink substitution for the new feature switch
- Add RuntimeHostConfigurationOption for the feature switch
- Remove default value for AndroidHttpClientHandlerType MSBuild property
- Add XA1042 error for NativeAOT when AndroidHttpClientHandlerType is set
- Add XA1043 deprecation warning for MonoVM/CoreCLR when AndroidHttpClientHandlerType is set
- Add XA1044 warning when XA_HTTP_CLIENT_HANDLER_TYPE is found in environment files
- Update tests to reflect new behavior
- Add documentation for new error/warning codes

Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature switch for HttpMessageHandler type [Trimming] Put HttpMessageHandler type resolution behind feature switch Jan 29, 2026
Copilot AI requested a review from simonrozsival January 29, 2026 11:29
Comment on lines +39 to +42
[FeatureSwitchDefinition ($"{FeatureSwitchPrefix}{nameof (XaHttpClientHandlerType)}")]
[FeatureGuard (typeof (RequiresUnreferencedCodeAttribute))]
internal static bool XaHttpClientHandlerType { get; } =
AppContext.TryGetSwitch ($"{FeatureSwitchPrefix}{nameof (XaHttpClientHandlerType)}", out bool isEnabled) ? isEnabled : XaHttpClientHandlerTypeEnabledByDefault;
Copy link
Member

Choose a reason for hiding this comment

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

@simonrozsival can we use the existing feature switch, and we don't need a new one?

We'd duplicate it in this file like we did StartupHookProvider.IsSupported.

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.

[Trimming] Put code for resolving HttpMessageHandler type name behind feature switch

3 participants