Is there a reason why a base class decorated with XmlInclude would still throw a type unknown exception when serialized?

The issue you are seeing is because the PaymentSummaryRequest is setting the Namespace. You can either remove the Namespace or add a Namespace to the PaymentSummary class: [XmlRoot(Namespace = Constants.Namespace)] [XmlInclude(typeof(xxxPaymentSummary))] public abstract class PaymentSummary { } As @Tedford mentions in his comment below the namespace is only required when using derived types. It looks … Read more

using XmlArrayItem attribute without XmlArray on Serializable C# class

The following should serialize properly the way you want. The clue being [XmlElement(“credentials”)] on the list. I did this by taking your xml, generating a schema (xsd) from it in Visual Studio. Then running xsd.exe on the schema to generate a class. (And some small edits) public class CredentialsSection { public string Username { get; … Read more

PHP Object as XML Document

I’d agree with using PEAR’s XML_Serializer, but if you want something simple that supports objects/arrays that have properties nested, you can use this. class XMLSerializer { // functions adopted from http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/ public static function generateValidXmlFromObj(stdClass $obj, $node_block=’nodes’, $node_name=”node”) { $arr = get_object_vars($obj); return self::generateValidXmlFromArray($arr, $node_block, $node_name); } public static function generateValidXmlFromArray($array, $node_block=’nodes’, $node_name=”node”) { $xml=”<?xml … Read more

What are the differences between the XmlSerializer and BinaryFormatter

The reason a binary formatter is able to deserialize directly to an interface type is because when an object is originally serialized to a binary stream metadata containing type and assembly information is stuck in with the object data. This means that when the binary formatter deserializes the object it knows its type, builds the … Read more

Which is the best alternative for Java Serialization?

It’s 2011, and in a commercial grade REST web services project we use the following serializers to offer clients a variety of media types: XStream (for XML but not for JSON) Jackson (for JSON) Kryo (a fast, compact binary serialization format) Smile (a binary format that comes with Jackson 1.6 and later). Java Object Serialization. … Read more

Can I make XmlSerializer ignore the namespace on deserialization?

Yes, you can tell the XmlSerializer to ignore namespaces during de-serialization. Define an XmlTextReader that ignores namespaces. Like so: // helper class to ignore namespaces when de-serializing public class NamespaceIgnorantXmlTextReader : XmlTextReader { public NamespaceIgnorantXmlTextReader(System.IO.TextReader reader): base(reader) { } public override string NamespaceURI { get { return “”; } } } // helper class to … Read more

Reading from memory stream to string

If you’d checked the results of stream.Read, you’d have seen that it hadn’t read anything – because you haven’t rewound the stream. (You could do this with stream.Position = 0;.) However, it’s easier to just call ToArray: settingsString = LocalEncoding.GetString(stream.ToArray()); (You’ll need to change the type of stream from Stream to MemoryStream, but that’s okay … Read more