473,786 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why I can serialize a LinkedList<myCl ass> ?

Hi All,
Is there a reason why it is not possible to serialize a geenric
LinkedList<Tobj ect containing a custom class marke serializable?
Thanks,

Alberto
Oct 28 '08 #1
5 4429
Alberto Bencivenni wrote:
Is there a reason why it is not possible to serialize a geenric
LinkedList<Tobj ect containing a custom class marke serializable?
It is possible over here:

using System;
using System.Collecti ons.Generic;
using System.Runtime. Serialization.F ormatters.Binar y;

[Serializable]
class A { }

class Program {
public static void Main() {
LinkedList<Al = new LinkedList<A>() ;
l.AddLast(new A());
new BinaryFormatter ().Serialize(Co nsole.OpenStand ardOutput(), l);
}
}

So you'll have to be more specific about your problem.

--
J.
Oct 28 '08 #2
http://connect.microsoft.com/VisualS...edbackID=93538
..
Posted by Microsoft on 11/11/2004 at 7:35 PM
We chose not to have a indexer method on LinkedList for performance reason.
So LinkedList will not be XMLSeriliazable .

"Alberto Bencivenni" <in**@devdept.c omwrote in message
news:e2******** *************** ***********@r15 g2000prh.google groups.com...
Hi All,
Is there a reason why it is not possible to serialize a geenric
LinkedList<Tobj ect containing a custom class marke serializable?
Thanks,

Alberto

Oct 28 '08 #3
Hi Jeroen,

Yes, we would like to serialize it via BinaryFormatter on a file on
disk.

FileInfo f = new FileInfo(filena me);

Stream myStream = f.OpenWrite();

BinaryFormatter myBinaryFormat = new BinaryFormatter ();

myBinaryFormat. Serialize(myStr eam, myLinkedList);

myStream.Close( );

Thanks,

Alberto
Oct 29 '08 #4
Alberto Bencivenni wrote:
Yes, we would like to serialize it via BinaryFormatter on a file on
disk.

FileInfo f = new FileInfo(filena me);

Stream myStream = f.OpenWrite();

BinaryFormatter myBinaryFormat = new BinaryFormatter ();

myBinaryFormat. Serialize(myStr eam, myLinkedList);

myStream.Close( );
This code works without any problems on my machine, for a trivial LinkedList
with only one element. So again: what's the *specific* error you run into?
There is no *fundamental* restriction on serializing a LinkedList, so
without more details of what "myLinkedLi st" is exactly and why it's not
working for you it's impossible to guess.

Here's the easy test for the most obvious thing that could be going wrong,
though: is your custom class actually serializable? Simply marking it
[Serializable] is not enough: all of its members (public and private) have
to be serializable too, for starters. Can you successfully serialize
individual instances of your class outside the LinkedList?

--
J.
Oct 29 '08 #5
sloan wrote:
http://connect.microsoft.com/VisualS...edbackID=93538
.
Posted by Microsoft on 11/11/2004 at 7:35 PM
We chose not to have a indexer method on LinkedList for performance reason.
So LinkedList will not be XMLSeriliazable .
Note that this talks about XmlSerializer, which has its own set of
restrictions. BinaryFormatter uses binary serialization and is much less
demanding.

--
J.
Oct 29 '08 #6

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

Similar topics

7
5831
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a brand new object when deserializing. In my case I have an existing object that I'd like to pass some XML to for the object to repopulate its member variables. Similarly I'd like it to be able to populate an XML string from the values of its member...
5
24723
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
10
4166
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName; string s_FinalFileName; try
3
10388
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll) . Thx in advance. Here is the part of the code: Regards MAY
2
8889
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
1
1468
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. Database.cs DatabaseFactory.cs DatabaseProviderFactory.cs DBCommandWrapper.cs
8
5468
by: cd~ | last post by:
I can provide a test app, the news server won't allow me to post the files because they are too large (93KB and 1.2KB) I downloaded the ESRI ArcXml schema and generated the classes from the schema using xsd.exe, which took a while because xsd doesn't handle recursive elements very well (StackOverFlow exception during generation). Now that I have the classes I am trying to serialize them to an xml document to send to ArcIMS to generate...
1
39704
by: Tim | last post by:
Could anyone tell me what this means and how do I correct it. Any suggestions? Thanks! Tim Richardson IT Developer and Consultant www.paladin3d.com Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same
4
7144
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming Building._Name to Building._BName in case the duplicate name was the issue, but that didn't help. Is there a native way to serialize nested objects, or will I have to write my own? public class LocationCell
9
1898
by: Gillard | last post by:
i get an exeption and i do not know what else to do to continue Dim sdf As New SaveFileDialog With sdf .AddExtension = True .DefaultExt = ".record" .FileName = Now.ToLongDateString .Filter = "recorder (*.record)|*.record" End With If sdf.ShowDialog = Windows.Forms.DialogResult.OK Then Dim Serializer As New
0
9647
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
9491
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
10357
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...
1
10104
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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
5397
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
4063
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
2
3668
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.