From 48435541cc139060b37e160f54ddc50a21a7b5b2 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 16 Jun 2025 18:32:28 +0000 Subject: [PATCH 1/3] Fix https://github.com/dotnet/runtime/issues/116698 --- ...HttpClientHandler.AnyMobile.InvokeNativeHandler.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs index 937bc237c3c739..8f18e5c1309170 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs @@ -11,6 +11,12 @@ using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; +#if TARGET_ANDROID +using GetHttpMessageHandlerReturnType = object; +#elif TARGET_IOS || TARGET_MACCATALYST || TARGET_TVOS +using GetHttpMessageHandlerReturnType = HttpMessageHandler; +#endif + namespace System.Net.Http { public partial class HttpClientHandler : HttpMessageHandler @@ -332,11 +338,10 @@ private void SetCredentials(ICredentials? value) private static HttpMessageHandler CreateNativeHandler() { - return (HttpMessageHandler)CallNative(); + return (HttpMessageHandler)CallNative(null); [UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetHttpMessageHandler")] - [return: UnsafeAccessorType(NativeHandlerType)] - static extern object CallNative(); + static extern GetHttpMessageHandlerReturnType CallNative([UnsafeAccessorType(GetHttpMessageHandlerType)] object? _); } } } From 065f6aa7d8bccd9a57d74c2cc86510a5c84190bb Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 16 Jun 2025 20:52:30 +0000 Subject: [PATCH 2/3] Fix build --- .../Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs index 8f18e5c1309170..d8613eabf4f4aa 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs @@ -14,7 +14,7 @@ #if TARGET_ANDROID using GetHttpMessageHandlerReturnType = object; #elif TARGET_IOS || TARGET_MACCATALYST || TARGET_TVOS -using GetHttpMessageHandlerReturnType = HttpMessageHandler; +using GetHttpMessageHandlerReturnType = System.Net.Http.HttpMessageHandler; #endif namespace System.Net.Http @@ -340,8 +340,10 @@ private static HttpMessageHandler CreateNativeHandler() { return (HttpMessageHandler)CallNative(null); +#pragma warning disable SA1121 // Use built-in type alias. We need to alias here for Android. [UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetHttpMessageHandler")] static extern GetHttpMessageHandlerReturnType CallNative([UnsafeAccessorType(GetHttpMessageHandlerType)] object? _); +#pragma warning restore SA1121 } } } From 5764f874be0dda585605271ed84a199afc892212 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 17 Jun 2025 08:21:42 -0700 Subject: [PATCH 3/3] React to https://github.com/dotnet/android/pull/10212 --- ...ttpClientHandler.AnyMobile.InvokeNativeHandler.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs index d8613eabf4f4aa..fbe67ae27b2cd8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.InvokeNativeHandler.cs @@ -11,12 +11,6 @@ using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; -#if TARGET_ANDROID -using GetHttpMessageHandlerReturnType = object; -#elif TARGET_IOS || TARGET_MACCATALYST || TARGET_TVOS -using GetHttpMessageHandlerReturnType = System.Net.Http.HttpMessageHandler; -#endif - namespace System.Net.Http { public partial class HttpClientHandler : HttpMessageHandler @@ -338,12 +332,10 @@ private void SetCredentials(ICredentials? value) private static HttpMessageHandler CreateNativeHandler() { - return (HttpMessageHandler)CallNative(null); + return CallNative(null); -#pragma warning disable SA1121 // Use built-in type alias. We need to alias here for Android. [UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetHttpMessageHandler")] - static extern GetHttpMessageHandlerReturnType CallNative([UnsafeAccessorType(GetHttpMessageHandlerType)] object? _); -#pragma warning restore SA1121 + static extern HttpMessageHandler CallNative([UnsafeAccessorType(GetHttpMessageHandlerType)] object? _); } } }