Re: Problem with MemoryStream

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 10/14/04


Date: Thu, 14 Oct 2004 15:52:10 +0100

Reshma Prabhu <ReshmaPrabhu@discussions.microsoft.com> wrote:
> I am trying to do an xsl tranformation from an XML file into
> another xml file. I want the output file to be in MemoryStream so that my
> dataset can direclty read xml using
> dataset.ReadXml(memoryStream).
>
> But at the time of reading it gives following exception
> System.Xml.XmlException: The root element is missing.

That's because you're writing the data to the memory stream, and then
trying to read from it without repositioning the "cursor" of the stream
to the start.

Put

mstream.Position = 0;

just before the call to ReadXml and you'll be fine.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Problem with MemoryStream
    ... another xml file. ... I want the output file to be in MemoryStream so that my ... dataset can direclty read xml using ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DataTable
    ... You could use XMLSerializer, and MemoryStream. ... As Follows(Replace Insect by ... DataTable and Stream by MemoryStream): ... > I need convert data from DataTable to XML file. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Serializing a Hashtable
    ... The first is that you don't really have to initialize the memory stream ... The other thing about this is that when you pass the byte array to the ... using (MemoryStream memoryStream = new MemoryStream()) ... // Serialize the instance. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dissappearing text in Byte[] conversion
    ... > MemoryStream which I convert a string through a Byte Array. ... My XML file is being truncated somewhere ... > int li = memStream.ReadmemStream.Length); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how do i create a new file -- in memory?
    ... and build the string with an in memory stream. ... MemoryStream ms = new MemoryStream; ... sw.WriteLine("foo bar foo bar foo bar foo bar"); ...
    (microsoft.public.dotnet.framework)