Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML.
Questions tagged [xmlserializer]
1432 questions
13
votes
5 answers
XmlSerializer serialize generic List of interface
I'm trying to use the XmlSerializer to persist a List(T) where T is an interface. The serializer does not like interfaces. I'm curious if there is a simple way to serialize a list of heterogeneous objects easily with XmlSerializer. Here's what I'm…

Steve
- 2,153
- 4
- 22
- 31
13
votes
3 answers
C# Xml Serializing List descendant with Xml Attribute
Morning Guys,
I have a collection that descends from List and has a public property. The Xml serializer does not pick up my proeprty. The list items serialize fine. I have tried the XmlAttribute attribute to no avail. Do you guys have a solution?
…

Steve
- 2,153
- 4
- 22
- 31
13
votes
4 answers
Is there a way to avoid the XmlSerializer to not initialize a null property when deserializing?
I have this class:
public class MySerializableClass
{
public List MyList { get; set; }
}
If MyList is null when MySerializableClass is serialized, I need to have it null when it's deserialised too, but the XmlSerializer always…

Carlo
- 25,602
- 32
- 128
- 176
12
votes
2 answers
Deserializing List with XmlSerializer Causing Extra Items
I'm noticing an odd behavior with the XmlSerializer and generic lists (specifically List). I was wondering if anyone has seen this before or knows what's going on. It appears as though the serialization works fine but the deserialization wants…

daveaglick
- 3,600
- 31
- 45
12
votes
2 answers
Why can XmlSerializer serialize abstract classes but not interfaces?
Edit This code should illustrate the whole problem:
[XmlInclude(typeof(AThing1))]
public abstract class AThing
{
public abstract string Name { get; set; }
}
[XmlInclude(typeof(IThing1))]
public interface IThing
{
string Name { get; set;…

Juan
- 15,274
- 23
- 105
- 187
12
votes
2 answers
XML, what is this: null or empty element?
Regarding to my other question: XML deserialize null elements?
I've got elements like these from a third-party server for API testing:
I just realized that now I am confusing myself about whether elements like…

Paul L
- 2,240
- 5
- 36
- 55
12
votes
2 answers
When is the class constructor called while deserialising using XmlSerializer.Deserialize?
My application saves a class away using XmlSerializer, and then later when required, creates an instance by deserialising it again.
I would like to use some property members of my class (assigned during deserialisation) in my constructor logic. It…

Satyajit
- 523
- 4
- 17
12
votes
3 answers
Can VS.NET 2010/MSBUILD produce XmlSerializers for .NET 3.5 SP1?
I just upgraded a VS 2008 solution containing WinForms, general use libraries, and a web app to VS 2010, but all projects still target .NET 3.5 SP 1. I use this technique to generate XmlSerializers for my general use libraries. The WinForms app runs…

flipdoubt
- 13,897
- 15
- 64
- 96
11
votes
1 answer
XML deserializing only works with namespace in xml
The most simple way I get ServiceStack xml deserialization to work is when the xml contains a namespace. However, the xml I receive do not contain namespaces. The most simple working example:
[Serializable]
public class test
{
}
class Program
{
…

user1154148
- 123
- 1
- 1
- 8
11
votes
4 answers
.NET XmlSerializer and nested classes in C#
I have encountered some surprising behavior using XmlSerializer in C#. Consider the following piece of code.
public class A : IEnumerable
{
public class B
{
[XmlAttribute]
public string PropA { get; set; }
…

Justin Aquadro
- 2,280
- 3
- 21
- 31
10
votes
3 answers
Overriding XML deserialization to use base deserialization and adding functionality
I have a class which should be serialized and deserialzed.
But every time after deserilization I need to call a method of synchronizing references.
Anyway I can implement the deserialization and use the traditional deserialization but add the call…

user271077
- 996
- 1
- 19
- 35
10
votes
2 answers
"The type or namespace name 'XmlSerializer' could not be found" error when System.Xml.dll is referenced
I've already wasted a few hours on this one:
XmlSerializer serializer;
YES, the using is there, the reference is there, I made the entire solution in VS2010 using .NET 4.0 so it's not any of those things. If I go in Object Explorer I can find the…

Ed Ayers
- 1,342
- 1
- 11
- 24
9
votes
1 answer
Extension method to serialize generic objects as a SOAP formatted stream
I'm having a hard time trying to figure out a generic extension method that would serialize a given object as SOAP formatted. The actual implementation looks somewhat like this:
Foobar.cs
[Serializable, XmlRoot("foobar"), DataContract]
public class…

Nano Taboada
- 4,148
- 11
- 61
- 89
9
votes
2 answers
Why does XmlSerializer fail to serialize enum value in .Net Core but works fine in .NET Framework
Summary
.NET Core apps fail to XML serialize an object which contains an enum value, while .NET Framework (4.7.2) succeeds. Is this a known breaking change, and if so, how can I work around it?
Code Example
The following console application does not…

Victor Chelaru
- 4,491
- 3
- 35
- 49
9
votes
3 answers
Performance: BinaryFormatter vs. XmlSerializer
I read very often that the BinaryFormatter has better performance then XmlSerializer.
Out of curiosity, I wrote a test-app.
a wtf moment... why is Xml so much faster than Bin (especially the deserialization)?
using System;
using…

Lukas
- 91
- 1
- 1
- 4