Reputation: 9784
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(url, UriKind.RelativeOrAbsolute));
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null || e.Cancelled)
{
//randomly, this code gets hit and
//there is no inner exception - just says "an exception occurred during a webclient request"
The error described in code happens randomly and if the same webclient request is made after that it works. Or if a new resource request is made the old one which got an error now comes before the new request......
This is very strange, any gurus here have a clue why it might be?
EDIT: information on error
System.Net.WebException: An exception occurred during a WebClient request. ---> System.Exception ---> System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component. at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) at System.Net.AsyncHelper.<>c_DisplayClass2.b_0(Object sendState) --- End of inner exception stack trace --- at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result) --- End of inner exception stack trace ---
The URL is a simple string having count of no more than 200.
Upvotes: 2
Views: 2720
Reputation: 1922
Probably URL is very long. I've same issue on WP8 with 2900 symbols length URL
Upvotes: 0
Reputation: 14561
I am going to hazard a guess that it's timing out. I am also going to further guess that it may be a DNS issue.
It's possible that the DNS is timing out. This would be consistent with you not seeing the request in Fiddler.
I suppose it's not impossible that the request would then be filled later when you try again, and this time the DNS works. Maybe. This point I'm a bit fuzzy on, but whatever.
If you use a URL with an IP address instead of a domain name, do you still have the same problem?
Upvotes: 0
Reputation: 39261
That code would be hit if cancelled or error being generated. I suspect you are hitting a networking issue, so I would fire up Fiddler and watch the HTTP requests and make sure you are getting them back correctly.
Upvotes: 2