Newlines in VB.NET XML literals

Viewed 110

Apparently, CR-LF-combinations in VB's XML literals get silently converted to LFs.

Consider the following minimal example:

Module Module1
    Sub Main()
        Dim x As XElement = <xml>1
2</xml>

        ' Print Bytes
        Console.WriteLine(String.Join("-", x.Value.Select(Function(c) AscW(c).ToString("X2"))))
    End Sub
End Module

Compiled with Visual Studio 2017 (Framework 4.5.2), this yields

31-0A-32

rather than

31-0D-0A-32

as I would have expected. I checked the source file with a binary editor and it definitely contains CR-LF (0D-0A) between 1 and 2 in the xml literal.

Is this officially documented behavior or just some implementation detail of my compiler that I cannot rely upon? If the former, where is it documented?

1 Answers
Related