M
Max Bolingbroke
Hi,
I have some extremely simple code using WebRequest (isolated from a
larger application):
static void Main()
{
WebRequest w = WebRequest.Create("http://
www.google.com"); // Works
//WebRequest w = WebRequest.Create(@"http://
finance.yahoo.com"); // Does not work
w.BeginGetResponse(
delegate(IAsyncResult ar)
{
try
{
//Console.WriteLine("Beginning to get the
response"); // Works if I insert this line
WebResponse r = w.EndGetResponse(ar);
Console.WriteLine(new
StreamReader(r.GetResponseStream()).ReadToEnd());
}
catch (Exception x)
{ Console.WriteLine(x.ToString()); }
}, null);
Thread.Sleep(Timeout.Infinite);
}
However, when I run the code as shown above (with or without Visual
Studio attached, in both Debug and Release mode) I get the following
exception message printed to the console:
System.IO.IOException: Unable to read data from the transport
connection: Attemp
ted to read or write protected memory. This is often an indication
that other me
mory is corrupt.. ---> System.AccessViolationException: Attempted to
read or wri
te protected memory. This is often an indication that other memory is
corrupt.
at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr
socketHandle, Byte* p
innedBuffer, Int32 len, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 s
ize)
--- End of inner exception stack trace ---
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at
DownloadTester.Program.<>c__DisplayClass1.<Main>b__0(IAsyncResult ar)
As the comments suggest, this same code works fine for retrieving a
page from Google or if I write something to the console before using
the response stream in the anonymous delegate! This is an extremely
puzzling result.
Can anyone shed some light on this problem?
Thanks in advance,
Max
I have some extremely simple code using WebRequest (isolated from a
larger application):
static void Main()
{
WebRequest w = WebRequest.Create("http://
www.google.com"); // Works
//WebRequest w = WebRequest.Create(@"http://
finance.yahoo.com"); // Does not work
w.BeginGetResponse(
delegate(IAsyncResult ar)
{
try
{
//Console.WriteLine("Beginning to get the
response"); // Works if I insert this line
WebResponse r = w.EndGetResponse(ar);
Console.WriteLine(new
StreamReader(r.GetResponseStream()).ReadToEnd());
}
catch (Exception x)
{ Console.WriteLine(x.ToString()); }
}, null);
Thread.Sleep(Timeout.Infinite);
}
However, when I run the code as shown above (with or without Visual
Studio attached, in both Debug and Release mode) I get the following
exception message printed to the console:
System.IO.IOException: Unable to read data from the transport
connection: Attemp
ted to read or write protected memory. This is often an indication
that other me
mory is corrupt.. ---> System.AccessViolationException: Attempted to
read or wri
te protected memory. This is often an indication that other memory is
corrupt.
at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr
socketHandle, Byte* p
innedBuffer, Int32 len, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 s
ize)
--- End of inner exception stack trace ---
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at
DownloadTester.Program.<>c__DisplayClass1.<Main>b__0(IAsyncResult ar)
As the comments suggest, this same code works fine for retrieving a
page from Google or if I write something to the console before using
the response stream in the anonymous delegate! This is an extremely
puzzling result.
Can anyone shed some light on this problem?
Thanks in advance,
Max