我在iPad上使用MonoTouch时遇到了以下崩溃。我已经在iOS 4.2+上测试过,它似乎发生在所有版本的iOS上。这是一个非常难以重现的,所以我没有一个好的测试用例。但是,在恢复应用程序时,我收到了很多崩溃。您可以在下面看到此崩溃收到的调用堆栈:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at System.Net.WebConnection.NextRead () [0x00000] in <filename unknown>:0
at System.Net.WebConnectionStream.ReadAll () [0x00000] in <filename unknown>:0
at System.Net.WebConnectionStream.CheckResponseInBuffer () [0x00000] in <filename unknown>:0
at System.Net.WebConnection.ReadDone (IAsyncResult result) [0x00000] in <filename unknown>:0
我的所有应用程序网络访问都包含在try / catch块中,并且是在一个单独的线程上发生的同步连接,这就是为什么这个调用堆栈让我难倒!
如果有人看到这个或知道原因,请告诉我。如果您有任何解决方法的建议,我也很乐意听到这些建议!
以下是标准线程操作的示例;请记住,所有这些代码都包含在try / catch中:
HttpWebRequest r = new HttpWebRequest(Configuration.MasterRequestUri);
r.UserAgent = Configuration.UserAgent;
r.Method = "POST";
r.ContentType = "application/x-www-form-urlencoded";
r.ContentLength = bytes.Length;
r.Timeout = 10000;
r.ReadWriteTimeout = 10000;
r.CachePolicy = Configuration.CachePolicy;
r.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
r.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
Stream s = r.GetRequestStream();
s.Write(bytes, 0, bytes.Length);
s.Flush ();
s.Close ();
WebResponse wr = r.GetResponse();
s = wr.GetResponseStream();
using(StreamReader sr = new StreamReader(s))
{
string responseString = sr.ReadToEnd();
// Parses the string and what not
}
答案 0 :(得分:0)
此问题在更高版本的Xamarin(MonoTouch)中自行消失,因此我认为这是当时使用的Mono版本中的错误。