|
-
Oct 31st, 2002, 05:14 PM
#1
Thread Starter
Member
xml and serilisation with queues??
is it possible to serilise a queue to xml??
i have the following code:
Code:
private void SaveToDisk(Queue ErrorList)
{
Stream s = new FileStream("errors.xml", FileMode.Create);
XmlSerializer b = new XmlSerializer(typeof(Queue));
b.Serialize(s, ErrorList);
s.Close();
}
but it failes with:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There was an error reflecting 'System.Collections.Queue'.
and it points to the line: XmlSerializer b = new XmlSerializer(typeof(Queue));
so can queues not be serlilised ?? I know hashtables cannot so does the same apply here??
-
Oct 31st, 2002, 07:11 PM
#2
PowerPoster
Here's a quick example:
Code:
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
public class SerializeEx
{
public static void Main()
{
string myName = "Bill Gates";
Queue myQueue = new Queue();
myQueue.Enqueue(myName);
FileStream serializeStream = new FileStream(@"c:\MyQueue.dat", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(serializeStream, myQueue);
serializeStream.Flush();
serializeStream.Close();
FileStream retrieveStream = new FileStream(@"c:\MyQueue.dat", FileMode.Open);
Queue newQueue = (Queue) bf.Deserialize(retrieveStream);
Console.Write(newQueue.Count);
}
}
-
Nov 1st, 2002, 03:58 AM
#3
Thread Starter
Member
can this not be done using xml then??
-
Nov 1st, 2002, 09:00 AM
#4
PowerPoster
Sure, use the SoapFormater class.
-
Nov 1st, 2002, 10:46 AM
#5
Thread Starter
Member
where is that??
i serched the help it could not find anything about a SoapFormater class, looked throught the object browser and still never found anything that looks like it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|