![Unexpected Unexpected](/uploads/1/2/5/3/125392340/918462416.png)
Welcome to the p2p.wrox.com Forums. You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting.
By you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free. Hi Group, I am trying to read xml response from a servlet using XmlTextWriter.
I am able to read the read half of the xml and suddenly an exception: “Unexpected end of file while parsing Name has occurred” is being thrown. Following is the part o xml I am trying to read: 1 001 DELOne Bridgestone HAR001 123.12 EURO 2 002 DELTwo Firestone HAR002 453.12 EURO 3 003 FIRESTONE HAR001 24.12 EURO When I am trying to read the FIRESTONE (In Third item in the list), I am getting the “Unexpected end of file while parsing Name has occurred” exception. I am able to read the values from element for first two elements. Following is the code I am using for reading the xml. Case 'BRAND': if (!xmlTextReader.IsEmptyElement) productInfo.Brand = xmlTextReader.ReadElementContentAsString; break; I also have searched net for this problem but I found nothing useful#61516; Please let me know if I am doing something wrong or missing on something. Thanks, Anup Daware Best Regards, Anup.
Hi Group, The problem is solved:) Following lines were creating the problem: StreamWriter streamWriter = new StreamWriter(responseStream); streamWriter.Write(responseXml); //responseXml is a string The the default buffer of StreamWriter is 4kb and the string responseXml is more than that, thus only a portion of my xml was being used by XmlTextWriter which is using responseStream: And that was the reason of Unexpected end of file while parsing Name has occurred exception. Solution: Rather than using the the StreamWriter, I directly used the responseStream.Write; for this I converted the string to byte array. Following is the code for it. String responseXml = GetResponseStream(uri, searchRequestXML); System.Text.UTF8Encoding ob = new UTF8Encoding; byte arr2 = ob.GetBytes(responseXml); responseStream.Write(arr2,0,arr2.Length); responseStream.Seek(0, SeekOrigin.Begin); XmlTextReader xmlTextReader = new XmlTextReader(responseStream) Well the conclusion is StreamWriter has a default size of 4KB which is not increased dynamically, and this is really unexpected.
![Unexpected End Of Part File Upload Unexpected End Of Part File Upload](http://www.codeguru.com/images/article/8459/Creating4.gif)
Best Regards, Anup Daware Best Regards, Anup.
Unexpected end of MIME multipart stream. MIME multipart message is not complete. Reading the request stream more than once will also cause this exception. I struggled with it for hours until I found a source explaining that the request stream only could be read once.
For those landing here googling: Unexpected end of MIME multipart stream. MIME multipart message is not complete.
Reading the request stream more than once will also cause this exception. I struggled with it for hours until I found a source explaining that the request stream only could be read once. In my case, I combined trying to read the request stream using a MultipartMemoryStreamProvider and at the same time letting ASP.NET do some magic for me by specifying parameters (coming from the request body) for my api method.