I'm refactoring my XML-serialization, and figured I'd try the DataContractSerializer. Everything runs smoothly, until it needs to serialize this class:
using System;
using System.Runtime.Serialization;
namespace VDB_Sync.Model
{
[DataContract(Name="Konstant")]
public class Konstant : DataFelt
{
[DataMember]
private MySqlDbType mydataType;
[DataMember]
private object value;
public Konstant(string navn, MySqlDbType dataType, object value)
: base(navn, dataType, "*Konstant", false, false)
{
//this.navn = navn;
this.mydataType = dataType;
this.value = value;
if (navn.Contains("*Løbenummer"))
{
navn = "*Konstant: " + Convert.ToString(value);
}
}
public object Value
{
get
{
return value;
}
}
}
}
It give's me this:
Type 'VDB_Sync.Model.Konstant' with data contract name 'Konstant:http://schemas.datacontract.org/2004/07/VDB_Sync.Model' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
*The help I've found so far points to collections and Types. I do have an enum (MySqlDbType) in my class - but get this: I even get the same error when i have no DataMembers declared at all :-x So - what's going on here? What am I missing?
for reference, this is how i serialized it, VDB_SessionController being the root:*
public void GemKonfig(VDB_SessionController session)
{
var settings = new XmlWriterSettings()
{
Indent = true,
IndentChars = "\t"
};
var writer = XmlWriter.Create(defaultFile, settings);
DataContractSerializer ser =
new DataContractSerializer(typeof(VDB_SessionController));
ser.WriteObject(writer, session);
writer.Close();
}