weird problem with XMLSerializer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Armond VanHeusen

    #1

    weird problem with XMLSerializer

    I have an application with a bunch of DLLs that are loaded in as plugins. In
    one of these I am trying to get XMLSerializatio n 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
    InvalidCastExce ption 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 GenerateStringT est() As String

    Dim x As New Test
    x.Quantity = 1000

    Dim xmlOut As XmlSerializer
    Dim stream_writer As MemoryStream

    Try
    xmlOut = New XmlSerializer(G etType(Test))
    stream_writer = New MemoryStream
    xmlOut.Serializ e(stream_writer , x) '<---- this line
    throws an InvalidCastExce ption
    stream_writer.C lose()
    Dim encoding As New UTF8Encoding
    Return encoding.GetStr ing(stream_writ er.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



  • Deepak

    #2
    RE: weird problem with XMLSerializer

    is the class marked by the serializable attribute?
    Look at the definition of the class Test
    Thanks
    Deepak
    "Armond VanHeusen" wrote:
    [color=blue]
    > I have an application with a bunch of DLLs that are loaded in as plugins. In
    > one of these I am trying to get XMLSerializatio n 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
    > InvalidCastExce ption 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 GenerateStringT est() As String
    >
    > Dim x As New Test
    > x.Quantity = 1000
    >
    > Dim xmlOut As XmlSerializer
    > Dim stream_writer As MemoryStream
    >
    > Try
    > xmlOut = New XmlSerializer(G etType(Test))
    > stream_writer = New MemoryStream
    > xmlOut.Serializ e(stream_writer , x) '<---- this line
    > throws an InvalidCastExce ption
    > stream_writer.C lose()
    > Dim encoding As New UTF8Encoding
    > Return encoding.GetStr ing(stream_writ er.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
    >
    >
    >
    >[/color]

    Comment

    Working...