Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
Questionc# literal conversion Pin
Chris Rickard20-Jul-07 9:33
Chris Rickard20-Jul-07 9:33 
AnswerRe: c# literal conversion Pin
Luc Pattyn20-Jul-07 17:45
sitebuilderLuc Pattyn20-Jul-07 17:45 
GeneralRe: c# literal conversion Pin
Chris Rickard20-Jul-07 18:07
Chris Rickard20-Jul-07 18:07 
GeneralRe: c# literal conversion Pin
Luc Pattyn20-Jul-07 18:21
sitebuilderLuc Pattyn20-Jul-07 18:21 
GeneralRe: c# literal conversion Pin
Chris Rickard20-Jul-07 18:32
Chris Rickard20-Jul-07 18:32 
QuestionRetrieve build-configuration in VS2003 Pin
AlexZieg7120-Jul-07 9:23
AlexZieg7120-Jul-07 9:23 
AnswerRe: Retrieve build-configuration in VS2003 Pin
Dave Kreskowiak20-Jul-07 9:55
mveDave Kreskowiak20-Jul-07 9:55 
QuestionMethods with generic value type parameters in C# [modified] Pin
gshen20-Jul-07 8:18
gshen20-Jul-07 8:18 
AnswerRe: Methods with generic value type parameters in C# Pin
Kevin McFarlane20-Jul-07 8:38
Kevin McFarlane20-Jul-07 8:38 
GeneralRe: Methods with generic value type parameters in C# Pin
gshen20-Jul-07 8:47
gshen20-Jul-07 8:47 
GeneralRe: Methods with generic value type parameters in C# Pin
Dave Kreskowiak20-Jul-07 9:01
mveDave Kreskowiak20-Jul-07 9:01 
GeneralRe: Methods with generic value type parameters in C# Pin
Kevin McFarlane20-Jul-07 9:02
Kevin McFarlane20-Jul-07 9:02 
GeneralRe: Methods with generic value type parameters in C# Pin
gshen20-Jul-07 9:10
gshen20-Jul-07 9:10 
GeneralRe: Methods with generic value type parameters in C# Pin
Dave Kreskowiak20-Jul-07 9:51
mveDave Kreskowiak20-Jul-07 9:51 
GeneralRe: Methods with generic value type parameters in C# Pin
Larantz21-Jul-07 9:51
Larantz21-Jul-07 9:51 
GeneralRe: Methods with generic value type parameters in C# Pin
Dave Kreskowiak22-Jul-07 4:21
mveDave Kreskowiak22-Jul-07 4:21 
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 

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.