weird problem with XMLSerializer

A

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
 
G

Guest

is the class marked by the serializable attribute?
Look at the definition of the class Test
Thanks
Deepak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top