XmlSerializer and Chars

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

From: RCIC (anonymous_at_discussions.microsoft.com)
Date: 05/07/04


Date: Fri, 7 May 2004 12:06:03 -0700

When serializing an object that has a Char as a property, the Char is converted into an Integer for some reason. See following code:

    Private Sub RunThisStupidExample()

        Dim myLetters As Letters = New Letters
        myLetters.Letter = "W"
        Dim strFile As String = "C:/Testing.xml"

        Dim myXmlSerializer As New System.Xml.Serialization.XmlSerializer(myLetters.GetType)
        Dim myFileStream As New System.IO.FileStream(strFile, System.IO.FileMode.Create)
        Dim myXmlTextWriter As New System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode)
        myXmlSerializer.Serialize(myXmlTextWriter, myLetters)

    End Sub

    Public Class Letters
        Dim _Letter As Char
        Public Property Letter()
            Get
                Return _Letter
            End Get
            Set(ByVal Value)
                _Letter = Value
            End Set
        End Property
    End Class

Does anyone know how to fix this.



Relevant Pages

  • Re: Malcolms new book
    ... negative yet you use a signed type which accepts negative values, ... *must* be some special reason for allowing negative length values. ... There are good reasons to use size_t for buffer sizes (mostly ... not prevent passing in a char, it simply requires that the value of the ...
    (comp.lang.c)
  • Re: Malcolms new book
    ... negative yet you use a signed type which accepts negative values, ... *must* be some special reason for allowing negative length values. ... Since a buffer can never have a size less than zero, ... not prevent passing in a char, it simply requires that the value of the ...
    (comp.lang.c)
  • Re: HELP!!
    ... char txtFile; ... getting Segmentation fault here** ... What if malloc() fails and returns a null pointer? ... reasonable implementation, but there's no reason not to avoid malloc ...
    (comp.lang.c)
  • Re: Comments on my code?
    ... value in a char *. ... void *malloc; ... There's simply no good reason not to ... You can still write working archaic code if ...
    (comp.lang.c)
  • Re: C89, size_t, and long
    ... The evidence you present suggests that they are incompetent. ... Suggesting that they are avoiding the standard headers because they think some implementation has headers broken enough that they have to be avoided does suggest they are incompetent. ... You also kept going on about how one reason for avoiding it could be to avoid broken standard headers. ... if char is not 8 bits you are stuffed in terms of finding an 8 bit type! ...
    (comp.lang.c)