diff --git a/mcs/class/System/System.Net/WebConnection.cs b/mcs/class/System/System.Net/WebConnection.cs index b154e0ff5ca7..d098948d71e3 100644 --- a/mcs/class/System/System.Net/WebConnection.cs +++ b/mcs/class/System/System.Net/WebConnection.cs @@ -639,14 +639,18 @@ internal void InitRead () { Stream ns = nstream; - try { - int size = buffer.Length - position; - currentNStreamReadAsyncResult = ns.BeginRead (buffer, position, size, ReadDone, null); - } catch (Exception e) { - HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead"); + if (ns != null) { + try { + int size = buffer.Length - position; + currentNStreamReadAsyncResult = ns.BeginRead (buffer, position, size, ReadDone, null); + } catch (Exception e) { + HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead"); + } + } else { + HandleError (WebExceptionStatus.ReceiveFailure, new ArgumentNullException("stream"), "InitRead"); } } - + static int GetResponse (WebConnectionData data, ServicePoint sPoint, byte [] buffer, int max) {