Reputation: 2780
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?
Upvotes: 8
Views: 10956
Reputation: 52083
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.
Upvotes: 8
Reputation: 64278
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.
Upvotes: 10