The following code throws "PlatformNotSupportedException" 'Operation is not supported on this platform"
It is a NET standard library (tried compiling against 1.4 and 2.0) that is referenced by a .NET 4.6.1 project that runs as a web app.
var handler = new HttpClientHandler();
handler.SslProtocols = SslProtocols.Tls12;
Why does Tls12 throw this exception and what is a workaround?
The problem here is that the SslProtocols
property doesn't exist on .NET Framework, it only exists in .NET Core.
You can see that in the Docs for HttpClientHandler
.
In .NET Framework you have to set it via ServicePointManager.SecurityProtocol
, i.e.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
To achieve that in your .NET Standard PCL you'll most-likely have to do cross-compile to netstandard-2.0 and net461 as I'm not sure it still exists in .NET Standard/.NET Core.
Alternatively, remove it from your PCL and set it globally in your .NET Framework application via the static property above.
This property was supposed to be implemented with .NET 4.7.1 per Microsoft docs and is actually implemented and working on .NET 4.7.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With