I get an exception for an object when I call the ReadToEnd method from a client-side method, getRecords, which communicates with a web server using StreamReader.
The first call to getRecords succeeds, only during the next call does an exception occur, and therefore I do not close and dispose of the StreamReader and the associated WebRequest properly.
I know that I could wrap these two objects in a using statement, however this just expanded into a try / catch / finally statement. As you can see from my code below, I clean up my final sentence.
Therefore, I either do not do something that uses the statment used, or there is something else that I can lose in my final status. . I would prefer not to use the statment used, if anything is possible, since I like my code.
Here is the code and the exception associated with it:
public int getRecords(string[] args, string[] vals) { List<string> urlList = BuildUrlRequestStrings(args, vals); WebRequest request = null; WebResponse wresponse = null; StreamReader sr = null; foreach (string url in urlList) { request = WebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/json";
07-02 11: 32: 15.076: I / <FI β> (2775): StorageRelayService.RequestQueueThread: EXCEPTION: System.ObjectDisposedException: the object was used after it was located. 07-02 11: 32: 15.076: I / <FI β> (2775): with System.Net.WebConnection.BeginRead (request System.Net.HttpWebRequest, Buffer System.Byte [], offset Int32, size Int32, System. AsyncCallback cb, System.Object state) [0x00000] at: 0 07-02 11: 32: 15.076: I / <FI β> (2775): with System.Net.WebConnectionStream.BeginRead (buffer System.Byte [], Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in: 0 07-02 11: 32: 15.076: I / <FI
(2775): in System.Net.WebConnectionStream.Read (buffer System.Byte [], offset Int32, size Int32) [0x00000] at: 0 07-02 11: 32: 15.076: I / <FI β> (2775) : with System.IO.StreamReader.ReadBuffer () [0x00000] at: 0 07-02 11: 32: 15.076: I / <FI β> (2775): with System.IO.StreamReader.Read (buffer System.Char [ ], index Int32, Int32 count) [0x00000] in: 0 07-02 11: 32: 15.076: I / <FI (2775): in System.IO.StreamReader.ReadToEnd () [0x00000] in: 0 07-02 11: 32: 15.076: I / <<FI β> (2775): with FieldInspection.Shared.Buffer.WSBuffer 1[FieldInspection.Shared.Model.AggregateRoot.Parcel].getRecords (System.String[] args, System.String[] vals) [0x00000] in <filename unknown>:0 07-02 11:32:15.076: I/<<< FI >>>(2775): at FieldInspection.Shared.Repository.REST.RepositoryREST 1 [FieldInspection. Shared.Model.AggregateRoot.Parcel] .read (Terms and Conditions) [0x00000] at: 0 07-02 11: 32: 15.076: I / <FI β> (2775): when FieldInspection.Shared.Model.DataAccess.ParcelRepositoryREST.parcelByIdList (System.Collections.Generic.List 1 parcelIdList, Boolean bCurrent, Boolean bHistorical) [0x00000] in <filename unknown>:0 07-02 11:32:15.076: I/<<< FI >>>(2775): at FieldInspection.Droid.StorageRelayService.ProcessRequestGetParcelCache (FieldInspection.Shared.Database.IPC.Request request) [0x00000] in <filename unknown>:0 07-02 11:32:15.076: I/<<< FI >>>(2775): at FieldInspection.Droid.StorageRelayService.ProcessRequestFromForegroundActivity (System.Collections.Generic.List 1 reqList) [0x00000] in: 0 07-02 11: 32: 15.076 : I / <<FI β> (2775): when FieldInspection.Droid.StorageRelayService.RequestQueueThread () [0x00000] at: 0
samosaris
source share