Questions tagged [xmlserializer]

Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML.

Description in Docs

1432 questions
118
votes
6 answers

Use the XmlInclude or SoapInclude attribute to specify types that are not known statically

I've got a very strange problem when working with .NET's XmlSerializer. Take the following example classes: public class Order { public PaymentCollection Payments { get; set; } //everything else is serializable (including other…
lsoliveira
  • 4,560
  • 3
  • 20
  • 31
68
votes
3 answers

XML Serialization and namespace prefixes

I'm looking for a way with C# which I can serialize a class into XML and add a namespace, but define the prefix which that namespace will use. Ultimately I'm trying to generate the following XML:
Aaron Powell
  • 24,927
  • 18
  • 98
  • 150
59
votes
4 answers

Reading from memory stream to string

I am trying to write an object to an Xml string and take that string and save it to a DB. But first I need to get the string... private static readonly Encoding LocalEncoding = Encoding.UTF8; public static string SaveToString (T…
tigerswithguitars
  • 2,497
  • 1
  • 31
  • 53
52
votes
3 answers

Why doesn't XmlSerializer support Dictionary?

Just curious as to why Dictionary is not supported by XmlSerializer? You can get around it easily enough by using DataContractSerializer and writing the object to a XmlTextWriter, but what are the characteristics of a Dictionary that makes it…
theburningmonk
  • 15,701
  • 14
  • 61
  • 104
52
votes
4 answers

C# XmlSerializer BindingFailure

I get a BindingFailure on a line of code using the XmlSerializer: XmlSerializer s = new XmlSerializer(typeof(CustomXMLSerializeObject)); The assembly with display name CustomXMLSerializeObject.XmlSerializers' failed to load in the 'LoadFrom'…
Steve H.
  • 3,283
  • 4
  • 24
  • 32
48
votes
6 answers

Memory Leak using StreamReader and XmlSerializer

I've been googling for the past few hours and trying different things but can't seem to the bottom of this.... When I run this code, the memory usage continuously grows. while (true) { try { foreach (string sym in stringlist) …
Alex999
  • 502
  • 2
  • 5
  • 8
47
votes
1 answer

Deserialize XML To Object using Dynamic

Is it possible Deserialize unknown XML to object like below? var xml = @"Arul90"; var serializer = new XmlSerializer(typeof(DynamicObject)); dynamic students =…
user1875919
  • 483
  • 1
  • 5
  • 4
46
votes
7 answers

XmlSerializer won't serialize IEnumerable

I have an invocation logger that is intended to record all method calls along with the parameters associated with the method using XmlSerializer. It works well for most of the calls, but it throws an exception for all methods that has a parameter of…
uni
  • 613
  • 1
  • 7
  • 11
43
votes
9 answers

XmlSerializer List Item Element Name

I have a class PersonList [XmlRoot("Persons")] PersonList : List when I serialize this to XML, by default it will produce something like this: ... ... My question is what needs to be…
Qstonr
  • 815
  • 1
  • 9
  • 11
43
votes
3 answers

Could not load file or assembly 'MyAssembly.XmlSerializers

I took a memory dump of IIS and while analyzing i found the error that said 'Could not load file or assembly MyAssemblyName.XmlSerializers'. In my code i am using XmlSerializer class to serialize and deserialize xml contents from xml file to custom…
sanjeev40084
  • 9,227
  • 18
  • 67
  • 99
36
votes
2 answers

XmlSerializer and nullable attributes

I have a class with numerous Nullable properties which I want to be serializable to XML as attributes. This is apparently a no-no as they are considered 'complex types'. So, instead I implement the *Specified pattern, where I create an addition…
Barg
  • 2,968
  • 7
  • 26
  • 28
31
votes
2 answers

ShouldSerialize*() vs *Specified Conditional Serialization Pattern

I am aware of both of the ShouldSerialize* pattern and the *Specified pattern and how they work, but is there any difference between the two? Are there any "gotchas" using one method vs the other when certain things should be serialized…
JNYRanger
  • 6,829
  • 12
  • 53
  • 81
31
votes
1 answer

Using XmlSerializer to create an element with attributes and a value but no sub-element

Hopefully this should be an easy answer for someone out there (and possibly a dupe), but I can't seem to figure it out. I need to output an element that looks like this: 37 I know how to get this:
user15486
26
votes
6 answers

How to write a comment to an XML file when using the XmlSerializer?

I have an object Foo which I serialize to an XML stream. public class Foo { // The application version, NOT the file version! public string Version {get;set;} public string Name {get;set;} } Foo foo = new Foo { Version = "1.0", Name = "Bar"…
Jensen
  • 3,498
  • 2
  • 26
  • 43
24
votes
1 answer

Chrome 22 outputs invalid XML when attributes have an xlink namespace

I have the following minimal JavaScript fragment: var xml = ''; var dom = new DOMParser().parseFromString(xml, 'text/xml'); xml = new XMLSerializer().serializeToString(dom); When I…
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
1
2 3
95 96