So I have the following code that uses and xsl file to transform an xml file to html and outputs it to a memory stream:
Code:
        Public Shared Function GetTransformedHTML(ByVal PesXmlDoc As Xml.XmlDocument, ByVal TransformFile As String) As IO.MemoryStream

            'create an XSL transformation
            Dim Transform As New System.Xml.Xsl.XslCompiledTransform
            Transform.Load(AppFramework.Configuration.ConfigFiles.GetConfigurationFileFullName(TransformFile))

            'perform the transform to an html file in the temp folder
            Dim OutStream As New IO.MemoryStream
            Transform.Transform(PesXmlDoc, Nothing, OutStream)
            Return OutStream

        End Function
Then, I output the memory stream to a file using the following:
Code:
                            Dim Writer As New IO.StreamWriter(OutputFileName)
                            Dim Buffer As Byte() = HtmlStream.GetBuffer
                            For I As Integer = 0 To Buffer.Length - 1
                                Writer.Write(Chr((Buffer(I))))
                            Next
                            Writer.Close()
It works great, except for one wrinkle. The first three characters in the file are "". They aren't in the xsl document nor in the xml document - near as I can tell. Where in the world did they come from?

I can hack my way around it by simply skipping the first 3 bytes of the memory stream, but that seems dangerous. What if 'in the wild' those first 3 characters aren't there, or maybe there will be 5, or maybe they will be somewhere else?

Any ideas anyone?