473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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

Nov 21 '05 #1
1 1197
is the class marked by the serializable attribute?
Look at the definition of the class Test
Thanks
Deepak
"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

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1387
by: Ot | last post by:
I have two different solutions that use xml serialization to create xml from a given class. The class is defined identically in both solutions. I copied the code for both the class and the code...
3
2096
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
3
4487
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
1
2177
by: Sacha | last post by:
I'm having trouble serializing some of my classes when using late binding. When I don't use late binding, it works fine. MyClass inherit from an abstract class called AbsMyClass. If I do the...
2
2715
by: Scott Reynolds | last post by:
I am having a problem exposing a class inherited from the collection base class as a webservice. If I expose the collection on a web page all works well and I am very happy. However when I try and...
7
5971
by: MrNobody | last post by:
I was a Java developer so I'm used to using property files as a means to keep configuration settings for my apps. I'm wondering what options are there with ..NET? Some settings I want to include...
10
3983
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
1
2076
by: Thomas S | last post by:
I want to serialize an object via XmlWriter, but when I serialize to that, 3 strange bytes are added to the beginning of the output (0xEF, 0xBB, and 0xBF) all of which are in the ASCII range (ASCII...
0
3170
by: Jamie | last post by:
I've implemented 3 classes, all of which make use of the IXmlSerializable interface. Class A has 2 properties that are instances to class B and C. Class A - serialization routine: public...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.