473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error Serializing a Wrapped SortedList

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

Oct 15 '08 #1
2 2698
Phil Galey wrote:
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/
Oct 16 '08 #2
Ok thanks, Martin.

Phil

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
Phil Galey wrote:
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/

Oct 16 '08 #3

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

Similar topics

7
by: Ook | last post by:
What am I doing wrong? This code gives a compile error: 'SortedList<T>::insert' : illegal call of non-static member function. I've tried several variations of this, but keep getting the same error....
2
by: sarah | last post by:
I keep getting the following error: g++ SortedList.cpp SortedList.cpp:260: error: expected constructor, destructor, or type conversion before '*' token SortedList.cpp:260: error: expected `,' or...
1
by: gerrod | last post by:
Hi - Does anyone know a way to created a SortedList (in the System.Collections namespace) that will sort on VALUES instead of KEYS... ? The scenario is this - I have a SortedList containing...
4
by: Dave Veeneman | last post by:
When does serializing objects make more sense than persisting them to a database? I'm new to object serialization, and I'm trying to get a feel for when to use it. Here is an example: I'm...
2
by: greg.merideth | last post by:
Is it possible to serialize SortedList<T,V> or do I need to come up with my own method to get the data into and out the list? I'm pretty sure I know that it's "no" I'm just curious if there are...
2
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
1
by: teddysnips | last post by:
Visual Studio 2005 I have a moderately complicated form. It has four User Controls, which are (somewhat simplified): 1. A tree control showing an employee hierarchy Below a tab strip with...
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
2
by: =?Utf-8?B?VGVk?= | last post by:
I have been asked to change an existing program which Implemented a Collection Class The current class had what is below (its just a summary of the code) Public Class FieldList Implements...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.