object to xml serialization error
<p>There was an error generating the XML document. Can anyone help?? The code is below. thanx in advance</p>

<pre><code> Public Shared Function toXml(ByRef objectToConvert As Object) As String


        Dim ns As New XmlSerializerNamespaces()


        Dim ms As New System.IO.MemoryStream()
        Dim xs As New System.Xml.Serialization.XmlSerializer(objectToConvert.GetType())
        Dim xtw As New System.Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8)

        xs.Serialize(xtw, objectToConvert, ns)
        ms = DirectCast(xtw.BaseStream, System.IO.MemoryStream)

        Return New UTF8Encoding().GetString(ms.ToArray())
    End Function
</code></pre>
