Connecting Tech Pros Worldwide Help | Site Map

Error Serializing a Wrapped SortedList

Phil Galey
Guest
 
Posts: n/a
#1: Oct 16 '08
I'm using VB.NET 2002 on Windows 2000 Pro and am having trouble serializing a SortedList.

This is my class:
<Serializable()Public Class clsGoodFiles
Inherits SortedList
Public Sub New()
MyBase.New()
End Sub
End Class

This is my calling code:

Dim xw As New Xml.XmlTextWriter(Path.Combine(Application.Startup Path, "GoodFiles.xml"), System.Text.Encoding.UTF8)
Dim xs As New Xml.Serialization.XmlSerializer(GetType(clsGoodFil es)) <=== ERROR LINE
Dim obj As New clsGoodFiles()
obj.Add("ABC.TIF", "A")
xs.Serialize(xw, obj)
xw.Close()
xw = Nothing
xs = Nothing
GC.Collect()

When it gets to the line indicated as ERROR LINE, it generates the following error:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There was an error reflecting 'WindowsApplication22.clsGoodFiles'.

This same technique works fine if I inherit an ArrayList. But ArrayList and SortedList both show Serializable in the documentation. Is there a way to get the serialization of the SortedList to work? Thanks.

Phil

Martin Honnen
Guest
 
Posts: n/a
#2: Oct 16 '08

re: Error Serializing a Wrapped SortedList


Phil Galey wrote:
Quote:
This same technique works fine if I inherit an ArrayList. But ArrayList
and SortedList both show Serializable in the documentation. Is there a
way to get the serialization of the SortedList to work?

I don't think so, when I try your code with VS 2003 then I get a more
specific error message:

Unhandled Exception: System.NotSupportedException: The type
ConsoleApplication35
..Module1+clsGoodFiles is not supported because it implements IDictionary.

So _XML serialization_ of that type is not supported. ArrayList does not
implement the interface IDictionary so it is different. And the
Serializable attribute refers to binary serialization, not XML
serialization.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Phil Galey
Guest
 
Posts: n/a
#3: Oct 16 '08

re: Error Serializing a Wrapped SortedList


Ok thanks, Martin.

Phil

"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:u99sQy3LJHA.1304@TK2MSFTNGP02.phx.gbl...
Quote:
Phil Galey wrote:
>
Quote:
This same technique works fine if I inherit an ArrayList. But ArrayList
and SortedList both show Serializable in the documentation. Is there a
way to get the serialization of the SortedList to work?
>
>
I don't think so, when I try your code with VS 2003 then I get a more
specific error message:
>
Unhandled Exception: System.NotSupportedException: The type
ConsoleApplication35
.Module1+clsGoodFiles is not supported because it implements IDictionary.
>
So _XML serialization_ of that type is not supported. ArrayList does not
implement the interface IDictionary so it is different. And the
Serializable attribute refers to binary serialization, not XML
serialization.
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Closed Thread