473,651 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.XmlTextWrit er(Path.Combine (Application.St artupPath, "GoodFiles.xml" ), System.Text.Enc oding.UTF8)
Dim xs As New Xml.Serializati on.XmlSerialize r(GetType(clsGo odFiles)) <=== ERROR LINE
Dim obj As New clsGoodFiles()
obj.Add("ABC.TI F", "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.Invalid OperationExcept ion' occurred in system.xml.dll
Additional information: There was an error reflecting 'WindowsApplica tion22.clsGoodF iles'.

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 2716
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.NotSuppo rtedException: The type
ConsoleApplicat ion35
..Module1+clsGo odFiles 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*******@yaho o.dewrote in message
news:u9******** ******@TK2MSFTN GP02.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.NotSuppo rtedException: The type
ConsoleApplicat ion35
.Module1+clsGoo dFiles 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
32092
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. template <typename T> class SortedList { public: void insert( T item); // Write this
2
1832
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 `;' before '*' token Line # 260 is ListNode *SortedList::copyList( ListNode *L ) { towards the end of the .cpp file. I have just put stubs in fr the code that I know works for readability purposes. here is my code:
1
20525
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 key-value pairs of UserID - DisplayName for a whole bunch of user objects. The UserID is simply a long, the DisplayName is something like, "Jones, Bill". I want the SortedList to sort the names alphabetically, rather than by
4
3614
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 writing an accounting application. I have a chart of accounts in the form of a containment hierarchy. A GeneralLedger contains a number of Accounts, and each of these Accounts can contain a Aubledger, which contains its own Accounts, and so on. The...
2
10190
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 any tricks around. Here's the error I get when I attempt to serialize a SortedList<T,V> Unhandled Exception: System.NotSupportedException: The type System.Collections.S ortedList is not supported because it implements IDictionary.
2
2040
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 have seen it looks like the Sorted List does not use the ^ while other variables do use the ^. I have used the SortedList with the ^ and gcnew and it seems to work fine. So the question is...
1
1499
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 three tabs: 1. A User Control containing a check box (AutoPostback = True), a
1
3898
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: System::Collections::SortedList, System::Collections::Generic::SortedList, using namespace System::Collections; using namespace System::Collections::Generic; Below is a working version of the generic template SortedList, which
2
1366
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 System.Collections.IEnumerable Private thisColl As Collection
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.