xmlserializer

Problem xml-deserializing recursive nested object

Solved: code below is not causing an infinite loop as I thought. the loop was in the code calling the deserialization. this posted code works just fine I am trying to serialize and deserialize to xml the following object public class MessageObjectCollection : List<MessageObject> { public string Serialize() { return XmlO...

Controlling order of serialization in C#

I'm using an XmlSerializer to serialize an object and write it to a file. I've had quite a bit of success with the serializer doing what I want it to do in terms of nesting elements and what is serialized as elements vs attributes. Unfortunately, I've run into a problem where I need one member of a class to serialize before another. E...

.NET, XmlSerializer InvalidOperationException, due to XmlSchema definition?

I've uploaded a ZIP file containing both the XML file I'm trying to read and the corresponding XSD files to http://www.bonnland.de/FIBEX.zip I'm trying to deserialize the following XML (fragment) using XmlSerializer. While doing so I get the error: (Sorry for it being German I'll give a rough translation in italics) System.InvalidOper...

C# Xml Serializing List<T> 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? public partial class MainWindow : Window { public MainWindow() { Init...

XmlSerializer.Deserialize - ignore unnecessary elements?

Hi, I've got an XSD schema which I've generated a class for using xsd.exe, and I'm trying to use XmlSerializer.Deserialize to create an instance of that class from an XML file that is supposed to conform to the XSD schema. Unfortunately the XML file has some extra elements that the schema is not expecting, which causes a System.InvalidOp...

Hard to decide between XML serialization options available in .NET

Until last night, I've been parsing XML using a variety of libraries in .NET -- XmlDocument and XDocument mostly. I'm not sure why I didn't look into this sooner, but it occurred to me that there must be something available in .NET that gives you class serialization / deserialization for free, and of course that comes in the form of the...

XmlSerializer replaces spaces with 0x0020 (the hex value)

For some reason, my XmlElements with spaces in them are printed with _x0020 in place of the space. For example, [XmlElement("The Total")] public double total { get; set; } turns into <The_0x0020_Total> when I print it out. I'm using a TextWriter to output, then I use XmlSerializer.Serialize to print to a file, but it's not working. ...

I Want to serialize with namespaces

I want to serialize the following structure in xml with C#. <?xml version="1.0" encoding="UTF-8"?> ... <complement> <hello:world color="0" number="1" > </complement> ... ... or something like that. I'm interested in namespaces and attributes serializing :P [(namespace)] class { } etc. Thanks ...

XmlSerializer special characters

Hi All, Currently I have the following code: namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var myObject = new MyObject() {Text = "€ 232.22"}; StringBuilder sb = new StringBuilder(); var xmlWriterSettings = new XmlWriterSettings(); ...

Xml DeSerialization from an internal node

I'm working on getting my .net object serialized\deserialized. As a requirement for our XML files, the object must be inside a master node named "MyCompany", here is an example for the file: <?xml version="1.0" encoding="utf-8"?> <mycompany> <station> <serial>VAA008090067</serial> </station> </mycompany> I'm running into an i...

XmlSerializer deserialize attribute with empty string to zero

I would like to use XmlSerializer and deserialize attributes with empty string values into zeros for ints. Every question I've seen regarding deserializing attributes with empty strings involves setting nullable ints to null - but I want to set non-nullable ints to zero, not null. Is there any easy way to do this without implementing I...

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: <Quantity foo="AB" bar="CD">37</Quantity> I know how to get this: <Quantity foo="AB" bar="CD"> <qty>37</qty> </Quantity> with a Quantity class containing ...

What is the difference between XmlArrayAttribute and XmlArrayItemAttribute?

What is the difference between XmlArrayAttribute and XmlArrayItemAttribute? Please explain both sides (i.e. serialzing and deserialzing). ...

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 System.Collections.Generic; using System.Runtime.Serialization; using System.Xml.Serialization; using Syste...

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 fine. When my web app tries to run using these libraries that reference the same XmlSeria...

Using XmlSerializer to create a non-standard element

I'm trying to create an XML output file to import into another program. The example XML file I was given looks like this: <SalesOrder> <OrderHeader> <BillTo> <EntityID>1234</EntityID> </BillTo> </OrderHeader> <LineItemList> <OrderLineComment> <LineItemID>1</LineItemID> </OrderLineComment> <LineI...

WCF method throws an exception of maximum items in an object graph is '65536'

I get an exception when there are too many objects returned: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://.../Contract:GetBlaBlaResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object ...

JSON.NET, XmlSerializer and "Specified" property

I have a REST service which takes JSON and XML as input and does a SOAP call to an extenal service with the deserialized content. The classes which are used for deserialization are auto-generated from the wsdl of the SOAP service. I use the XmlSerializer in case of a XML request and I want to use the Newton JSON.NET JsonSerializer for JS...

How to XML-serialize a dictionary

I have been able to serialize an IEnumerable this way: [XmlArray("TRANSACTIONS")] [XmlArrayItem("TRANSACTION", typeof(Record))] public IEnumerable<BudgetRecord> Records { get { foreach(Record br in _budget) { yield return br; } } } However, I realised that now I need a dictionary contai...

WCF XMLSerializerFormat: I keep getting casting errors if I use it!

I keep getting an error when I have an interface with more than one method tagged with the XMLSerializerFormatAttribute and I'm not sure why... [ServiceContract(Namespace = "http://www.mysite.com/Services/Foo", ConfigurationName = "IFoo")] public interface IFoo { [OperationContract(Action = "http://www.mysite.com/Services/Foo/Select...