While testing code using HttpWebRequest it can be observed in the debug output that a number of exceptions are thrown within the GetResponse call of a HttpWebRequest. If you run exactly the same code on the desktop you don't see this behaviour. For reference the following is a simple example which displays the issue:-
System.Net.WebRequest request = System.Net.WebRequest.Create("http://www.microsoft.com");System.Net.WebResponse webResponse = request.GetResponse();webResponse.Close();
Since the exceptions are caught it doesn't stop the code from running but I considered it annoying enough to investigate and try to find the cause. Here is the typical output during the call to GetResponse:-
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dllA first chance exception of type 'System.UriFormatException' occurred in System.dllThe thread 0x577c6eaa has exited with code 0 (0x0).The thread 0xaf16af8a has exited with code 0 (0x0).A first chance exception of type 'System.UriFormatException' occurred in System.dllThe thread 0x577c6eaa has exited with code 0 (0x0).The thread 0xaf16af8a has exited with code 0 (0x0).The thread 0xaf399a02 has exited with code 0 (0x0).
I eventually tracked it down to an issue with WebProxy. It occurs if you do not specify a Proxy or use the system proxy:-
request.Proxy = System.Net.GlobalProxySelection.Select;
If you won't be using a proxy you can set the Proxy property to an empty WebProxy:-
request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy();
After making this change you'll see the method progress without any exceptions - you'll just see the 5 thread exit notifications in the output. Whether or not this makes a noticeable difference to performance I have yet to discover but it does indicate an underlying issue since the desktop has no such problem.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.