问题
I have an exception I can't handle properly in Xamarin.Forms due to a missing member in the WebExceptionStatus enumeration, namely the NameResolutionFailure member.
Does anyone know how I can properly handle the exception in this specific case?
回答1:
When looking at a previous version of the WebExceptionStatus enumeration, the NameResolutionFailure member is not supported in a PCL.
What you can do to handle this issue is as follows:
case (System.Net.WebExceptionStatus)1:
// your code
Or:
catch (System.Net.WebException ex)
{
if ((int)ex.Status == 1)
// your code
)
I tested this by simply throwing a new WebException like this:
throw new System.Net.WebException("Test", (System.Net.WebExceptionStatus)1);
Which, as I thought, returned an exception with NameResolutionFailure being the StatusCode.
来源:https://stackoverflow.com/questions/41413172/xamarin-system-net-webexception-missing-webexceptionstatus-nameresolutionfailure