Skip to content

[.NET] Implement NSUrlSessionHandler members that throw PlatformNotSupportedException #14632

Closed

Description

@rolfbjarne

We have numerous NSUrlSessionHandler properties that throw PlatformNotSupportedException, and which we could/should implement properly:

https://github.com/xamarin/xamarin-macios/blob/0924eb4ef11f509e48a132c22ec1ad8fdc7be3c1/src/Foundation/NSUrlSessionHandler.cs#L532-L675

Ref: #13579
Proxy support is also tracked here: #18635.

Activity

  1. added
    enhancement
    dotnet
    on Apr 4, 2022
  2. added this to the .NET 7 milestone on Apr 4, 2022
  3. rolfbjarne commented on Apr 26, 2022

    @rolfbjarne
    MemberAuthor

    @mandel-macaque do you know the answer to ^?

  4. filipnavara commented on Apr 26, 2022

    @filipnavara
    Member

    While this gets fixed, how can we test apps connecting to local services with self-signed certs?

    Import the certificate to keychain and mark it as trusted I guess.

  5. modified the milestones: .NET 7, .NET 8 on Aug 26, 2022
  6. kfuller002 commented on Sep 10, 2022

    @kfuller002

    Can someone elaborate on the workaround for this? As it seems this just got pushed to .NET 8?

  7. kfuller002 commented on Sep 10, 2022

    @kfuller002

    I was able to get around this by Updating my iOS Build settings Linker behavior to "Dont Link"
    image

  8. rolfbjarne commented on Sep 12, 2022

    @rolfbjarne
    MemberAuthor

    ServerCertificateCustomValidationCallback is being implemented in #15117. We haven't had time to look at the other members yet.

  9. softlion commented on Sep 24, 2022

    @softlion

    We haven't had time to look at the other members yet.

    Proxy / UseProxy is required for apps running on restricted government mobile devices, as the MDM forces the proxy on every allowed devices, and the default .net behavior is to force the use of no proxy (ie: it ignores the system wide proxy set on mobile device).

  10. Ghostbird commented on Feb 7, 2023

    @Ghostbird

    Even if this isn't immediately merged. Maybe it would be nice to early return some no-op actions?
    I had to hunt down a bug today in an iOS app where a class that used HTTP crashed. The weird thing was that the HTTP code itself was definitely not using proxies at all. It said so right at the start where it initialised the HttpClientHandler:

        HttpClientHandler hch = new()
        {
          Proxy = null,
          UseProxy = false
        };

    In retrospect this was pretty funny. On iOS proxying is not supported, but not proxying is not supported either. It only works if you use the defaults, which, of course, do not proxy. The unnecessary lines were in shared code originally written for .NET Core 1 in 2017 and removing them made it work. In fact it turned out that the entire constructor of that class could be replaced by instead initialising the HttpClient member with = new(). All the work we did there was initialising values, apparently necessary in .NET Core 1, which have since become auto-initialised defaults.

  11. 3 remaining items

  12. modified the milestones: .NET 8, .NET 9 on Sep 12, 2023
  13. weedcry commented on Dec 13, 2023

    @weedcry

    @softlion @rolfbjarne @filipnavara
    I am using a proxy for ios in the following way:
    Refer to this discussion 86364

    var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;
    
    var dictionary = new NSDictionary(
        new NSString("HTTPEnable"), 1,
        new NSString("HTTPProxy"), ProxyServer,
        new NSString("HTTPPort"), ProxyPort,
        new NSString("HTTPSEnable"), 1,
        new NSString("HTTPSProxy"), ProxyServer,
        new NSString("HTTPSPort"), ProxyPort);
    
    configuration.ConnectionProxyDictionary = dictionary;
    var handler =  NSUrlSessionHandler(configuration);
    var httpClient = new HttpClient (handler);
    

    Using this method, I have been able to send requests through the proxy server.
    Do you think this method is okay? Will there be any impact when the proxy setting of NSUrlSessionHandler is not supported?

  14. moved this to Technical Debt in .NET 9on Aug 27, 2024
  15. modified the milestones: .NET 9, .NET 10 on Sep 27, 2024
  16. added
    networking
    on Oct 10, 2025
  17. modified the milestones: .NET 10, .NET 11 on Oct 22, 2025
  18. added a commit that references this issue on Sep 2, 2026
    c298be9
  19. added a commit that references this issue on Oct 14, 2026
    72b7bed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetenhancementnetworking

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions