Bug 42174 - using webclient to download https crashes app on bad cert
Summary: using webclient to download https crashes app on bad cert
Alias: None
Product: iOS
Classification: Xamarin
Component: Mono runtime / AOT compiler ()
Version: XI 9.6 (iOS 9.3)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
Depends on:
Reported: 2016-06-26 03:51 UTC by Ian
Modified: 2016-06-27 15:40 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ian 2016-06-26 03:51:12 UTC
When you attempt to download a string with the web client from a server https://someplace.com and the cert is no longer valid, your app will explode.

try {
            string url = "https://somewebsiteWithBadCert.com";
            var webClient = new System.Net.WebClient ();
            webClient.DownloadStringCompleted += (sender, e) => {

               json = e.Result;
               ///blah blah
            webClient.DownloadStringAsync (new Uri (url));
         } catch {

even the try catch doesn't catch it
Comment 1 Vincent Dondain [MSFT] 2016-06-27 15:20:41 UTC

Your try/catch is around the async call instead of being inside the delegate.

Something like that works just fine to handle expired certificates (;

string url = "https://expired.badssl.com/";
var webClient = new System.Net.WebClient ();
string json = null;
webClient.DownloadStringCompleted += (sender, e) => {
    try {
        json = e.Result;
        ///blah blah
    } catch {
        Console.WriteLine ("We entered the catch!");
webClient.DownloadStringAsync (new Uri (url));
Comment 2 Vincent Dondain [MSFT] 2016-06-27 15:40:41 UTC
If the issue you're experiencing is different, please include a self-contained test case so we can easily reproduce.