when i compile the code below and i run it, i've got the following
exception:
Unhandled Exception: System.InvalidOperationException: The type Car was
not expected. Use the XmlInclude or SoapInclude attribute to specify
types that are not known statically.
can you help me, how can i solve it? how to serialize the non primitive
type (ArrayList with the instances of the Car class)?
thanks
mirek
mirek wrote:
try to compile this code:
using System;
using System.IO;
using System.Collections;
using System.Xml.Serialization;
public class Car
{
public string type;
public int price;
public Car( string type, int price )
{
this.type = type;
this.price = price;
}
}
public class Config
{
static string filename = ".configrc";
public ArrayList list;
public Config()
{
list = new ArrayList();
}
public void Add( string type, int price )
{
Car car = new Car( type, price );
list.Add( car );
}
public void Save( Config config )
{
using (FileStream fs = new FileStream(filename, FileMode.Create)) {
XmlSerializer serializer = new XmlSerializer(typeof(Config));
serializer.Serialize(fs, config);
}
}
}
class App
{
public static void Main()
{
Config config = new Config();
config.Add( "truck", 200 );
config.Add( "pickup", 100 );
Console.WriteLine( "hello" );
config.Save( config );
}
}
mirek
Robert Jordan wrote:
mirek wrote:
hello
i try to use serialization for storing of configuration in my app.
the problem is, i've got some data stored in ArrayList, and they are
not primitive types - they are instances of classes or some structs.
so it looks like this:
[Serializable]
public class Entry
{
public string type;
public int price;
}
[Serializable]
public class CConfiguration
{
...
public ArrayList vehicle;
...
}
// in my app...
Entry e = new Entry();
e.type = "truck";
e.price = 200;
vehicle.Add( e );
but it doesnt work. how can i do that?
What doesn't work? Did your get an exception? If so, which one?
Robert
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
--
e-mail: [EMAIL PROTECTED]
icq: 113397932
jabber: [EMAIL PROTECTED]
homepage: http://www.intrak.sk/~binas
english:
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
slovak:
prosim, neposielajte mi prilohy vo formatoch .doc a .ppt (power point)
precitajte si http://www.fsf.org/philosophy/no-word-attachments.cs.html
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list