[MonoTouch] 100% NullReferenceException in HttpWebRequest.GetRequestStream()
Robert Jordan
robertj at gmx.net
Mon Oct 10 07:47:11 EDT 2011
Hi Will,
On 09.10.2011 21:40, Will Stones wrote:
> Since upgrading to MonoTouch 4.2.2 and MonoDevelop 2.8 I'm experience a 100%
> NullReferenceException when making a call to
> HttpWebRequest.GetRequestStream() when running on an iOS 3.1.3 device. I've
> pasted the exception trace below.
>
> The code which reproduces the exception is as follows:
> HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
> request.UserAgent = "MyUserAgent";
> request.Timeout = 15000;
> request.KeepAlive = true;
> request.Method = "POST";
> string requestString = GetQueryString();
> byte[] postBytes = Encoding.ASCII.GetBytes(requestString);
> request.ContentLength = postBytes.Length;
> request.ContentType = "application/x-www-form-urlencoded";
> // Crashes on this line
> request.GetRequestStream().Write(postBytes, 0, postBytes.Length);
>
>
> The code used to work fine until I upgraded MT and MD (I'm afraid I've lost
> the installers for the versions I was using so I can't tell you when the
> problem was introduced).
>
> This issue is pretty critical for me...! Can anyone confirm how long a fix
> for an issue like this is likely to take? If you'd like any more info on
> this please let me know.
This looks like a bug in MT 4.2 new feature: "iOS Proxy support: we now
pick the system proxy settings and use those in .NET APIs. The new
CFProxy type can be used to get to all the details."
As a workaround, try to set request's Proxy property like this:
request.Proxy = GlobalProxySelection.GetEmptyWebProxy();
Robert
More information about the MonoTouch
mailing list