Hello all,
For the life of me, I can't figure out why the xmlwirter writes an extra "?" at the begining of the xml.
Hope one of you can spot what I've wrong...
Below is the code to demonstrate that behavior.
Code:
 Using ms As New MemoryStream()
            Dim settings As New XmlWriterSettings()
            With settings
                .CloseOutput = False
                .CheckCharacters = True
                .OmitXmlDeclaration = False
                .Encoding = Encoding.GetEncoding("UTF-8")
                .Indent = True
                .IndentChars = "    "
                .ConformanceLevel = ConformanceLevel.Document
            End With

            Dim writer As XmlWriter = XmlWriter.Create(ms, settings)
            With writer
                ms.Position = 0
                .WriteStartDocument()
                .WriteStartElement("AccessRequest")
                .WriteAttributeString("xml", "lang", Nothing, "en-US")
                .WriteElementString("AccessLicenseNumber", "12345")
                .WriteElementString("UserId", "my user id")
                .WriteElementString("Password", "my password")
                .WriteEndElement()
            End With
            writer.Flush()
            writer.Close()
            ms.Position = 0

            Dim size As Integer = CInt(ms.Length)
            Dim buffer(size - 1) As Byte
            ms.Read(buffer, 0, size)
            Dim output As String = Encoding.UTF8.GetString(buffer)
            Console.Write(output)
        End Using
And this is the output. Note the red "?" at the beginning of the xml. Upon close examination, it's a Chr(239) but in console application, it is shown as the "?"
Code:
?<?xml version="1.0" encoding="utf-8"?>
<AccessRequest xml:lang="en-US">
    <AccessLicenseNumber>12345</AccessLicenseNumber>
    <UserId>my user id</UserId>
    <Password>my password</Password>
</AccessRequest>