webclient randomly crashing

  • Thread starter Thread starter loris128
  • Start date Start date
L

loris128

Hi
I'm writing a simple application using a Webclient class to get
informations
from the internet.
My problem is that I am randomly getting a
'System.NullReferenceException' in system.dll with no apparent reason
and *only in debug mode*.

I'm using Visual Studio 2003, with the .net framework v1.1.4322

Steps to reproduce the error:
- Create a new windows application project containing a form and a
button.
- On the button click event instantiate a new webclient and call the
OpenRead method.
- run the application in debug, click the button and DON'T CLOSE your
form
- do anything for a pair of minutes, take a coffee, check your mail...
- a System.NullReferenceException is cast!

Could it be a bug in the garbage collector while in debug?

Thanks
 
Ok, I've finally sorted it out...
For anyone intrested, read:
http://addressof.com/blog/archive/2004/04/26/636.aspx
and
http://addressof.com/blog/archive/2004/04/26/637.aspx

in short: it's most likely a problem on KeepAlive connections on
systems running
internet monitoring software and antivirus, such as NOD32.
The trick is replacing webclient calls with HttpWebRequest/response
calls
(doing all the web calls manually...) and setting httpwebrequest's
keepalive to false.....

here is some sample code:

HttpWebRequest tReq =
(HttpWebRequest)HttpWebRequest.Create(parAddress);
tReq.KeepAlive=false;
HttpWebResponse tResp=tReq.GetResponse();
Stream tStream=tResp.GetResponseStream();
....

Needless to say, this is nothing more than a hack, but it works fine
here.
I hope .net2 has a better webclient implementation!
 
Back
Top