Home All Groups Group Topic Archive Search About

weird problem with XMLSerializer

Author
29 Jun 2005 5:05 PM
Armond VanHeusen
I have an application with a bunch of DLLs that are loaded in as plugins. In
one of these I am trying to get XMLSerialization to work but with little
success. I then tried some very simple code shown below as a quick and dirty
test. The kicker is that it works perfectly in the EXE and every DLL except
one. In the one I need it to as a matter of fact. The symptoms is that no
exception is thrown unless I am in the Exceptions window (the CTRL+ALT+E
one) and have Break Into Debugger set, at which point I am told there is an
InvalidCastException with no further information detailed. If I disable the
'Break Into Debugger' then no exception is raised at all but the code skips
a line and nothing gets outputted.

Does anybody have any diea what could possibly make this identical code work
in one place but not another?


module Test

            Public Function GenerateStringTest() As String

                Dim x As New Test
                x.Quantity = 1000

                Dim xmlOut As XmlSerializer
                Dim stream_writer As MemoryStream

                Try
                    xmlOut = New XmlSerializer(GetType(Test))
                    stream_writer = New MemoryStream
                    xmlOut.Serialize(stream_writer, x) '<---- this line
throws an InvalidCastException
                    stream_writer.Close()
                    Dim encoding As New UTF8Encoding
                    Return encoding.GetString(stream_writer.ToArray())
                Catch ex As Exception
                    Return ""
                End Try

            End Function

end module


Public Class Test
    Public Quantity As Double
    Public Sub New()
    End Sub
End Class

Author
3 Jul 2005 7:45 PM
Deepak
is the class marked by the serializable attribute?
Look at the definition of the class Test
Thanks
Deepak
Show quoteHide quote
"Armond VanHeusen" wrote:

> I have an application with a bunch of DLLs that are loaded in as plugins. In
> one of these I am trying to get XMLSerialization to work but with little
> success. I then tried some very simple code shown below as a quick and dirty
> test. The kicker is that it works perfectly in the EXE and every DLL except
> one. In the one I need it to as a matter of fact. The symptoms is that no
> exception is thrown unless I am in the Exceptions window (the CTRL+ALT+E
> one) and have Break Into Debugger set, at which point I am told there is an
> InvalidCastException with no further information detailed. If I disable the
> 'Break Into Debugger' then no exception is raised at all but the code skips
> a line and nothing gets outputted.
>
> Does anybody have any diea what could possibly make this identical code work
> in one place but not another?
>
>
> module Test
>
>             Public Function GenerateStringTest() As String
>
>                 Dim x As New Test
>                 x.Quantity = 1000
>
>                 Dim xmlOut As XmlSerializer
>                 Dim stream_writer As MemoryStream
>
>                 Try
>                     xmlOut = New XmlSerializer(GetType(Test))
>                     stream_writer = New MemoryStream
>                     xmlOut.Serialize(stream_writer, x) '<---- this line
> throws an InvalidCastException
>                     stream_writer.Close()
>                     Dim encoding As New UTF8Encoding
>                     Return encoding.GetString(stream_writer.ToArray())
>                 Catch ex As Exception
>                     Return ""
>                 End Try
>
>             End Function
>
> end module
>
>
> Public Class Test
>     Public Quantity As Double
>     Public Sub New()
>     End Sub
> End Class
>
>
>
>