xml-serialization

How do you serialize/deserialize a list of objects with a common root class?

Related: How can I use polymorphism in XML Serialization? I have a class I wrote for serializing the user's preferences to disk between application sessions. To read/write I'm using XmlSerializer.Deserialize() and XmlSerializer.Serialize(). One property that gets serialized is a list of sub-settings for different application compon...

XmlSerializer with parameterless constructor with no public properties or fields... Is it possible?

Having the following class (.Net 3.5): public class Something { public string Text {get; private set;} private Something() { Text = string.Empty; } public Something(string text) { Text = text; } } This serializes without error but the resulting XML does not include the Text property since ...

Creating an extensible properties class (OOP)

I have an application which supports multiple types and versions of some devices. It can connect to these devices and retrieve various information. Depending on the type of the device, I have (among other things) a class which can contain various properties. Some properties are common to all devices, some are unique to a particular devi...

How Can I Make the XmlIgnore Attribute Method-Specific in a WebService (ASP.Net)?

I understand that I can make the property nullable or use a bool called [PropertyName]Specified to determine whether the property is serialized to XML, but I would like the auto-generated examples to hide these elements in one method's definition, and show them in another. This way the user knows whether they'll be there or not. For ex...

.Net XML Serialization and Escaped or Encoded characters

I'm using XML Serialization heavily in a web service (the contracts pass complex types as params). Recently I noticed that the .Net XML Serialization engine is escaping some of the well known 5 reserved characters that must be escaped when included within an element (<, >, &, ' and "). My first reaction was "good old .Net, always looking...

C# Custom Xml Serialization

I'm attempting to deserialize a custom class via the XmlSerializer and having a few problems, in the fact that I don't know the type that I'm going to be deserializing (it's pluggable) and I'm having difficulty determining it. I found this post which looks similar but can't quite get it to work with my approach because I need to deseria...

How Do I serialize a COM object in .Net?

Hi, I need serialize a Com Object using .net using c# or Delphi .Net is this possible? Bye. ...

.net XmlSerializer, ignore base class properties

Lets say we have a derivided class "SerializableLabel" from the base class "System.Windows.Controls. [XmlRoot("SerializableLabel")] public class SerializableLabel : Label { public string foo = "bar"; } I'd like to serialize this class but ignore ALL of the properties in the parent class. Ideally the xml would look something like: ...

.Net XML Serialization issue

Hello everyone, My confusion is, I am using .Net C# XMLSerializer to serialize a customize defined type, using the schema/cs file generated by XSD tool from an input original XML file. But the generated serialized XML file namespace is different from original XML input file. Especially from original XML file, Envelope belongs to namespa...

How to serialize ObjectContext into XML like in DataSets (XML database)?

Hi In datasets there was a method WriteXml or ReadXml Does anyone have any idea on how to this with Entity Framework? Has anyone implemented this before? ...

Is there any point Unit testing serialization?

I have a class that serializes a set of objects (using XML serialization) that I want to unit test. My problem is it feels like I will be testing the .NET implementation of XML serialization, instead of anything useful. I also have a slight chicken and egg scenario where in order to test the Reader, I will need a file produced by the Wr...

Consuming SOAP Web Service, error when de-serializing value types

Does anybody know how I can troubleshoot web services responses? When I get my soap message back from a web service call I get this error "The string '' is not a valid AllXsd value" as soon as it's a value type like a datetime per example. My proxy classes are generated from wsdl's using wsdl.exe, the wsdl seems valid. I have seen not...

LINQ, custom objects, serialization and object references

Hi, I'm currently using LINQ to SQL for data retrieval and then populating my custom objects with LINQ queries. My custom objects inherit from a base class that uses the IsReference = true attribute in the datacontract. I'm then taking my object hierarchy and serializing it to XML which is then sent off to a service. This works however...

Custom node names with XML serialization (.NET)

I have the following code: public class Foo {} static class Program { [XmlElement("foo")] // Ignored :( static public List<Foo> MyFoos { get; private set; } public static void Main() { MyFoos.Add(new Foo()); MyFoos.Add(new Foo()); XmlSerializer configSerializer = new XmlSerializer(type...

validating JAXB, but whitespace not ignored

some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out of tutorials online. JAXBContext jc = JAXBContext.newInstance( "xmlreadtest" ); Unmarshaller u = jc.createUnmarshaller(); // setting up for validation. SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_...

Serializing a generic collection with XMLSerializer in VB.NET

Why won't XMLSerializer process my generic list? Sub Main() Serializing() End Sub <System.Serializable()> _ Public Class User Public Sub New() End Sub Public Sub New(ByVal Username As String, ByVal UserId As Integer) Name = Username ID = UserId End Sub Public Name As String Public ID As Int...

XML deserialization 'standardising' line endings, how to stop it? (.NET)

I have a class with a property marked with [XmlText], that accepts multiline input. In my XML file, I've verified that the line endings inside the text content are infact "\r\n", the same as the rest of the file. The code I'm using to deserialize is: XmlSerializer configSerializer = new XmlSerializer(typeof(WorldList)); string file = "...

Why isn't there an XML-serializable dictionary in .NET?

I need an XML-serializable dictionary. Actually, I now have two quite different programs that need one. I was rather surprised to see that .NET doesn't have one. I asked the question elsewhere and got sarcastic responses. I don't understand why it's a stupid question. Can someone enlighten me, given how dependent various .NET featur...

XmlSerializer giving FileNotFoundException at constructor

An application I've been working with is failing when i try to serialize types. A statement like this: XmlSerialzer lizer = new XmlSerializer(typeof(MyType)); Produces: System.IO.FileNotFoundException occurred Message="Could not load file or assembly '[Containing Assembly of MyType].XmlSerializers, Version=1.0.0.0, Culture=neutral...

Why does XmlSerializer requires the classes of the serialized object declared as public?

It's totally well known that in order to be able to serialize your objects using XmlSerializer you have to declare their classes as public -otherwise you get an InvalidOperationException. The question here is why? I Googled and I found out that XmlSerializer actually generates and compiles a brand new assembly and then uses this assembly...