Hi guys,
I am serializing a Dictionary<Guid,SomeClass> to an XML file using DataContractSerializer and
XmlWriter.
When using 'XmlWriterSettings() { Indent=true }' (and the Dictionary contains more than one entry)
the de-serialization (using DataContractSerializer and Stream) breaks with the following exception:
$ mono ./DictSerializer.exe
System.Runtime.Serialization.SerializationException: Deserializing type
'System.Collections.Generic.Dictionary`2[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[DictSerializer.Bit, DictSerializer, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]'. Expecting state 'EndElement'. Encountered state 'Element'
with name 'd2p1:KeyValueOfguidBit' with namespace
'http://schemas.microsoft.com/2003/10/Serialization/Arrays'. (10,6)
at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader,
System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap
(System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in
<filename unknown>:0
...
This is with mono-2.10.1, MS .NET 4 is fine.
Attached a minimal application that demonstrates this behaviour.
What's the established procedure to file a bug?
Cheers,
/uli
--
Ulrich Hertlein
Research and Development mailto:[email protected]
XDT Pty Ltd http://www.xdt.com.au
namespace DictSerializer
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
/// <summary>
/// A class that contains stuff.
/// </summary>
[DataContract]
public class Bit
{
public Bit(string which)
{
this.Which = which;
}
[DataMember]
public string Which { get; set; }
}
/// <summary>
/// A class that contains a dictionary.
/// </summary>
[DataContract]
public class Stuff
{
public Stuff(string destination)
{
this.Bits = new Dictionary<Guid, Bit>();
this.Bits[Guid.NewGuid()] = new Bit(destination);
this.Bits[Guid.NewGuid()] = new Bit(destination);
}
[DataMember]
public Dictionary<Guid, Bit> Bits { get; set; }
}
class Program
{
static void Main(string[] args)
{
try
{
// Setup
Stuff a = new Stuff("a");
string path = "stuff.xml";
// Serialize to file
{
DataContractSerializer ds = new
DataContractSerializer(a.GetType());
XmlWriterSettings settings = new XmlWriterSettings() {
Indent = true };
using (XmlWriter s = XmlWriter.Create(path, settings))
{
ds.WriteObject(s, a);
}
}
// De-serialize from file
{
DataContractSerializer ds = new
DataContractSerializer(typeof(Stuff));
using (Stream s = File.OpenRead(path))
{
Stuff b = (Stuff)ds.ReadObject(s);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list