Search code examples
c#azurexamarintls1.2azure-api-apps

How to enable TLS 1.2 support in an Xamarin Android application C#


I'm developing a Xamarin project. With the help of C# code, I need to access the azure API for my project. It produces the following error 'Could not create a secure channel'. So I'm using the following line of code

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

But also after adding the line, it throws the same error.

But when I compile the same code from the console application it produces the result. Is there any problem with my code or with my mobile device?


Solution

  • Refer the link for this issue. https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/http-stack?tabs=macos

    Windows: Project Options > Android Options, then click the Advanced Options button. Mac: Project Options > Build > Android Build settings and click on the General tab.

    This is not "my answer". Somebody mentioned this in the above comment section.