Results 1 to 5 of 5

Thread: xml and serilisation with queues??

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39

    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??

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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);
    	}
    
    }

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39
    can this not be done using xml then??

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Sure, use the SoapFormater class.

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39
    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
  •  



Click Here to Expand Forum to Full Width