Click here to Skip to main content
15,900,325 members
Home / Discussions / C#
   

C#

 
QuestionDetecting when multiple BackgroundWorkers are finished Pin
dilucidate20-Jul-07 8:05
dilucidate20-Jul-07 8:05 
AnswerRe: Detecting when multiple BackgroundWorkers are finished Pin
led mike20-Jul-07 8:23
led mike20-Jul-07 8:23 
GeneralRe: Detecting when multiple BackgroundWorkers are finished Pin
dilucidate20-Jul-07 8:48
dilucidate20-Jul-07 8:48 
GeneralRe: Detecting when multiple BackgroundWorkers are finished Pin
led mike23-Jul-07 5:02
led mike23-Jul-07 5:02 
QuestionFocusable Panel Pin
Sukhjinder_K20-Jul-07 7:14
Sukhjinder_K20-Jul-07 7:14 
AnswerRe: Focusable Panel Pin
Judah Gabriel Himango20-Jul-07 7:29
sponsorJudah Gabriel Himango20-Jul-07 7:29 
GeneralRe: Focusable Panel Pin
Sukhjinder_K20-Jul-07 7:39
Sukhjinder_K20-Jul-07 7:39 
QuestionSerialization of arrays Pin
Rudolf Jan20-Jul-07 7:05
Rudolf Jan20-Jul-07 7:05 
I want to serialize an array of objects, using the SOAP formatter. However, when serializing the second object, I get an exception that says I cannot add the same object twice to a serialization info. I wrote a small application to demonstrate the problem:

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Xml;
using System.Runtime.Serialization.Formatters.Soap;

namespace Serialization
	{
	// Create a class to include in the list
	[Serializable]
	public class MyObject:ISerializable
		{
		public Int32 idx=0;

		public MyObject(Int32 i)
			{
			idx=i;
			}

		public virtual void GetObjectData(SerializationInfo info,StreamingContext context)
			{
			info.AddValue("Idx",idx);
			}
		}

	// The objectlist consists of a list of MyObjects
	[Serializable]
	class ObjectList: ISerializable
		{
		public List<MyObject> TheList;

		public ObjectList()
			{
			TheList=new List<MyObject>(10);
			MyObject tmp=new MyObject(1);
			TheList.Add(tmp);
			tmp=new MyObject(2);
			TheList.Add(tmp);
			}

		public virtual void GetObjectData(SerializationInfo info,StreamingContext context)
			{
			Int32 i=0;

			for(i=0;i<2;i++)
				{
				if(TheList[i]!=null)
					{
					// Serialize a MyObject contained in TheList
					// This does not work for the second occurrence of MyObject
					TheList[i].GetObjectData(info,context);
					}
				}
			}
		}

	class Program
		{
		static void Main(string[] args)
			{
			ObjectList MyObjectList=new ObjectList();
			FileStream WriteStream=new FileStream("test.xml",FileMode.Create); 
			SoapFormatter bfor=new SoapFormatter();
			bfor.Serialize(WriteStream,MyObjectList);
			}
		}
	}


In the sample I create a class MyObject. Objects of type MyObject are stored in an ObjectList object, which essentially is a wrapper around a LIST<myobject> generic List object.

I have no idea what I'm doing wrong. I did not find any samples on how to handle array serialization. Please note that the application I develop is far more complex than this. Therefore I do not want to use automatic serialization. I use the SOAP formatter because it is easier to debug. Later I will switch to the binary formatter.

Tanks in advance for your advice.

Rudolf Heijink
AnswerRe: Serialization of arrays Pin
led mike20-Jul-07 7:14
led mike20-Jul-07 7:14 
GeneralRe: Serialization of arrays Pin
Rudolf Jan23-Jul-07 2:56
Rudolf Jan23-Jul-07 2:56 
GeneralRe: Serialization of arrays Pin
Rudolf Jan23-Jul-07 8:03
Rudolf Jan23-Jul-07 8:03 
GeneralRe: Serialization of arrays Pin
led mike23-Jul-07 8:23
led mike23-Jul-07 8:23 
GeneralRe: Serialization of arrays Pin
Rudolf Jan5-Aug-07 10:07
Rudolf Jan5-Aug-07 10:07 
QuestionShowing form window above task bar. Pin
kaleem tarar20-Jul-07 6:48
kaleem tarar20-Jul-07 6:48 
QuestionHow to install an addin for Visual Studio .NET 2005 Pin
imagic20-Jul-07 6:35
imagic20-Jul-07 6:35 
AnswerRe: How to install an addin for Visual Studio .NET 2005 Pin
Judah Gabriel Himango20-Jul-07 7:31
sponsorJudah Gabriel Himango20-Jul-07 7:31 
GeneralRe: How to install an addin for Visual Studio .NET 2005 Pin
imagic20-Jul-07 18:53
imagic20-Jul-07 18:53 
GeneralRe: How to install an addin for Visual Studio .NET 2005 Pin
imagic20-Jul-07 22:49
imagic20-Jul-07 22:49 
QuestionReplacing pictures Pin
eskape1920-Jul-07 5:30
eskape1920-Jul-07 5:30 
AnswerRe: Replacing pictures Pin
Luc Pattyn20-Jul-07 5:56
sitebuilderLuc Pattyn20-Jul-07 5:56 
QuestionUpload a file to my server Pin
Raymond_P*20-Jul-07 5:07
Raymond_P*20-Jul-07 5:07 
AnswerRe: Upload a file to my server Pin
led mike20-Jul-07 7:04
led mike20-Jul-07 7:04 
GeneralRe: Upload a file to my server Pin
Raymond_P*20-Jul-07 7:08
Raymond_P*20-Jul-07 7:08 
GeneralRe: Upload a file to my server Pin
led mike20-Jul-07 7:11
led mike20-Jul-07 7:11 
GeneralRe: Upload a file to my server Pin
Raymond_P*20-Jul-07 7:33
Raymond_P*20-Jul-07 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.