Vovich
Vovich

Reputation: 321

An exception of type 'System.Net.WebException'

I'm working on WP7-8 application which is using RestClient for getting info from WebServer. When I swich off internet connection I see:

An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

What does it mean? How or should I fix it? My code:

 RestSharp.RestClient _client;
_client = new RestClient { BaseUrl = BaseURL };
_client.Timeout = 50;

resourceString = "Http:\\blablabla"; 
var request = new RestRequest { RequestFormat = DataFormat.Xml, Resource = resourceString };
request.Timeout = 50;
request.IncreaseNumAttempts();

if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() != true)
{
    ErrorCallback("Internet connection Error");
    return;
}
_client.ExecuteAsync(request, response =>
{
    return response;
}

Upvotes: 0

Views: 13614

Answers (2)

fillobotto
fillobotto

Reputation: 3785

That exception is a TimeoutException. You must increase the Timeout property in order to let it complete the request, let's say to set it to 4000.

Upvotes: 2

Den
Den

Reputation: 16826

Here is the gist of the problem - the WebException is a generic way to tell you that something went wrong with the connection without necessarily telling you what it is. It is all-encompassing, if you want to look at it this way.

To actually get the reason the problem showed up, you will need to read the response inside the catch block - the server will give you more details.

Upvotes: 1

Related Questions