Hi all,
We have problems deseralizing objects previously serialized as XML.
This did work fine with .NET 1.1 but since we have installed SP1,
deserializing fails (but serializing works). The error occurs within
the following line "return formatter.Deser ialize(xmlReade r) as
ParameterList;" and the "innerexception " sais "The root element is
missing.".
Thanks for any hints
Chrigel
Here is the code:
--------------
using System;
using System.Windows. Forms;
using System.IO;
using System.Xml.Seri alization;
namespace ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
ParameterList l = new ParameterList() ;
string s = l.SerializeToSt ring();
l = null;
l = ParameterList.D eserialize(s);
s = "";
}
catch(Exception e)
{
MessageBox.Show (e.Message);
}
}
}
[Serializable]
[XmlType("Parame terList1")]
public class ParameterList
{
public string a = "";
public ParameterList()
{
a = "hugo";
}
public static ParameterList Deserialize(str ing sVesselData)
{
MemoryStream stream = new MemoryStream();
byte[] bytes = System.Text.Enc oding.UTF8.GetB ytes(sVesselDat a);
stream.Write(by tes,0,bytes.Len gth);
XmlSerializer formatter = new XmlSerializer(t ypeof(Parameter List));
System.Xml.XmlT extReader xmlReader = new
System.Xml.XmlT extReader(strea m);
stream.Seek(0,0 );
return formatter.Deser ialize(xmlReade r) as ParameterList;
}
public string SerializeToStri ng()
{
System.IO.Memor yStream stream = new System.IO.Memor yStream();
System.Xml.Seri alization.XmlSe rializer formatter = new
XmlSerializer(t ypeof(Parameter List));
System.Xml.XmlT extWriter xmlWriter = new
System.Xml.XmlT extWriter(strea m,System.Text.E ncoding.UTF8);
xmlWriter.Flush ();
stream.Seek(0,0 );
formatter.Seria lize(xmlWriter, this);
return System.Text.Enc oding.UTF8.GetS tring(stream.Ge tBuffer());
}
}
}