diff --git a/mcs/class/System/System.Net/WebConnection.cs b/mcs/class/System/System.Net/WebConnection.cs index 322d26f81aba..8283454e23b1 100644 --- a/mcs/class/System/System.Net/WebConnection.cs +++ b/mcs/class/System/System.Net/WebConnection.cs @@ -576,14 +576,18 @@ internal void InitRead () { Stream ns = nstream; - try { - int size = buffer.Length - position; - ns.BeginRead (buffer, position, size, ReadDone, ns); - } catch (Exception e) { - HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead"); + if (ns != null) { + try { + int size = buffer.Length - position; + ns.BeginRead (buffer, position, size, ReadDone, ns); + } 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) {