xmlserializer

[C#] Is XmlRootAttribute inheritable?

I have a class I am serializing with C#'s XmlSerializer. It is marked with the XmlRoot attribute, and I would like to inherit this attribute in a derived class. Looking at the documentation it does not say that XmlRoot sets Inherit to false with AttributeUsageAttribute (Inherit is supposed to default to true), but I get an error when tr...

XmlSerializer bug when serializing collection of collections without root element?

This is a bit of a long question, but I've made it as terse as possible, so please bear with me. It looks to me like a bug in the XmlSerializer class but before I file it with Microsoft I'd like to see if there's anything I've missed, which is entirely possible. I'm attempting to generate the following XML as a representative case, whic...

XmlSerializer.Deserialize on a List<> item

Hi all I've tried all the solutions I could find on SO and elsewhere, but can't seem to figure out why this is not working. Straightforward deserialization of an XML string into an object, the object has one property - a List: [XmlTypeAttribute(AnonymousType = true)] public class UpdateData { [XmlArrayItem(ElementName = "Updates...

.Net Serialization, XmlDataReader, a SQL Database and the FlagsAttribute!

Giving a quick overview of my situation: I am working on an N-Tier app that relies a lot on serialization, objects interact with the database mainly in a serialized fashion, objects and collections are inserted, updated and read as XML from within stored procedures. For some of the smaller data classes I am simply using ExecuteNonQuery...

xmlserializer not correctly deserializing schema with import

I've been trying to deserialize an xml file in C# with classes generated from schemas in xsd.exe. Unfortunately only part of the file is being properly deserialized, the rest is returned as null for reasons I can't work out. My process is as follows: Starting with the myschema.xsd file from which the C# code is generated: <?xml versio...

Represent XML without xsd

Note: I cannot use XSD... not going to go into why. I'm having a problem properly representing the following xml in a class that it should get deserialized into: XML: <product> <sku>oursku</sku> <attribute name="attrib1">value1</attribute> <attribute name="attrib2">value2</attribute> <attribute name="attribx">valuex</attri...

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<MyObject> 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 initializes it when it deserialises my class. Is there a way to avoid it initializing null pro...

XML Serialization - Is it possible to serialize a model in this way?

I have the following model: public class ABaseObject { private Guid id = Guid.NewGuid(); public ABaseObject() { } public Guid ID { get { return id; } } } public class ADerivedObject : ABaseObject { public ADerivedObject() { } public string Name { get; set; } } public class AObjectCollection<T> { ...

XmlSerializer property deserializing order

Just wondering if anyone knows how the XmlSerializer determines the order for deserializing any given object's properties. Added info: I have a class like this: private bool _hasGaps = false; public bool HasGaps { get { return _hasGaps; } set { _hasGaps = value; } } priv...

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' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNot...

xml serialization with custom value format

Hi, I have lots of xml strings, one of its element value can be 'False' or 'True'. I created a class with a bool type property for that element. When deserialize the xml strings, it throws an error saying those values are not valid boolean value. I can't change the value in the xml, what could I do to be able to deserialize it? Thanks,...

XmlSerializer List Item Element Name

HI Hope someone can help me on this. Say, I have an object of class [XmlRoot("Persons")] PersonList : List<Human> , when serialize this object to xml, by defualt it will produce something like this: <Persons><Human>.......</Human><Human>.......</Human></Persons> My question is what need to be done in order to change element Hum...

XmlSerializer to Deserialize and return the first row

Hi I have a xml that look like: . . I post the code: public interface ImmoListItem { LISTRow[] items { get; set; } } public partial class XMLImmo : ImmoListItem { private LIST LISTdata; public XMLImmo(string query) { StringReader reader = new StringReader(query); ...

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: <myNamespace:Node xmlns:myNamespace="..."> <childNode>something in here</childNode> </myNamespace:Node> I know with both the DataContract...

XmlSerializer is throwing InvalidOperationException when using the generic type constraint where

When I try to run the following code (two separated assemblies) ClassLibrary.cs public interface ITest { } Program.cs using System; public class TestClass { public void Test<T>(T x) where T : ITest { } } static class Program { static void Main(string[] args) { new System.Xml.Serialization.XmlSerialize...

Why is XmlReader appending namespace uris to each element?

I've got a Stream containing xml in the following format that I want to deserialize into C# objects <?xml version="1.0" encoding="utf-8" standalone="yes"?> <OrganisationMetaData xmlns="urn:organisationMetaDataSchema"> <Organisations> <Organisation> <Code>XXX</Code> <Name>Yyyyyy</Name>... I've done this loads of t...

How can I validate the output of XmlSerializer?

In C# / .NET 2.0, when I serialize an object using XmlSerializer, what's the easiest way to validate the output against an XML schema? The problem is that it is all too easy to write invalid XML with the XmlSerializer, and I can't find a way to validate the XML that does not look cumbersome. Ideally I would expect to set the schema in ...

XmlSerializer.Deserialize() is too slow with files over 1MB - .Net compact framework 3.5 sp1

Hi, I got a XML schema for which I used xsd.exe to generate a Class FooClass. I am receiving xml requests from host which I get them from a directory and use the XmlSerializer.Deserialize() to get a Instance of my FooClass. Well, this worked till now perfectly and it still does, but suddenly I started to get XML files which are larger...

Handling FormatExceptions using XmlSerializer.Deserialize

I have a third party web service that returns this xml <book> <release_date>0000-00-00</release_date> </book> I am trying to deserialize it into this class public class Book { [XmlElement("release_date")] public DateTime ReleaseDate { get; set; } } But because 0000-00-00 isn't a valid DateTime, I get a FormatException. Wh...

How do I add a default namespace with no prefix using XMLSerializer

Hi Using C# and .Net 3.5; I am trying to generate an XML document that contains the default namespace without a prefix using XMLSerializer. eg. <?xml version="1.0" encoding="utf-8" ?> <MyRecord ID="9266" xmlns="http://www.website.com/MyRecord"&gt; <List> <SpecificItem> using the following code string xmlizedString = nul...