xmlserializer

XmlSerializer extraTypes memory leak

雨燕双飞 提交于 2019-12-04 03:44:05
问题 I'm developing some application, wich calls lot of XmlSerializer constructor with extraTypes parametr. I've find out, that each call encrease application memory for about 100KB and 2 descriptors (sometimes more). Code example: this code encrease application memory for 100KB and 2 handlers per each call while (true) { Console.ReadLine(); new XmlSerializer(typeof (object), new Type[] {}); } this code encrease application memory for 43024KB and 2004 handlers for (var i = 0; i < 1000; i++) { new

How to read XML file using XmlSerializer C# [duplicate]

安稳与你 提交于 2019-12-04 02:35:19
问题 This question already has an answer here : Deserialization of xml file by using XmlArray? (1 answer) Closed 3 years ago . I have a problem when I want to read XML file by using XmlSerializer. My xml file like follow : <?xml version="1.0" encoding="utf-8"?> <contents> <section id="1"> <element1>2</element1> <element2>1</element2> <idx>1</idx> <idx>2</idx> <idx>3</idx> </section> <section id="2"> <element1>2</element1> <element2>1</element2> </section> <section id="3"/> </contents> Here are the

WCF: provide generic FaultException in IErrorHandler

你说的曾经没有我的故事 提交于 2019-12-03 13:32:08
Some context: We have a custom XSD and generate the WSDL and C# code using WSCF.blue. The client side uses ChannelFactory<T> and shares the interface which includes all the attributes added by WSCF.blue to match what is in the XSD. I'm trying to implement IErrorHandler.ProvideFault where it provides a generic FaultException<T> , but on the client side I'm getting back a non-generic FaultContract . This is what my ProvideFault method looks like: public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { if (!(error is FaultException)) { FaultException faultException

When is the class constructor called while deserialising using XmlSerializer.Deserialize?

别等时光非礼了梦想. 提交于 2019-12-03 11:25:07
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 is ok to assume that the properties will be assigned first, and once all properties are assigned will the constructor be called? Continuing on this topic, is there any documentation available on the sequence of events that take place during deserialisation? No it is not OK to assume the properties will be set when the constructor runs. The opposite

Using generics with XmlSerializer

为君一笑 提交于 2019-12-03 09:04:47
问题 When using XML serialization in C#, I use code like this: public MyObject LoadData() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyObject)); using (TextReader reader = new StreamReader(settingsFileName)) { return (MyObject)xmlSerializer.Deserialize(reader); } } (and similar code for deserialization). It requires casting and is not really nice. Is there a way, directly in .NET Framework, to use generics with serialization? That is to say to write something like: public MyObject

XmlSerializer and nullable attributes

末鹿安然 提交于 2019-12-03 06:36:47
问题 I have a class with numerous Nullable<T> 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 *Value and *Specified property as follows: [XmlIgnore] public int? Age { get { return this.age; } set { this.age = value; } } [XmlAttribute("Age")] public int AgeValue { get { return this.age.Value; } set { this.age = value; } } [XmlIgnore] public

remove encoding from xmlserializer

痞子三分冷 提交于 2019-12-03 03:00:50
I am using the following code to create an xml document - XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); new XmlSerializer(typeof(docket)).Serialize(Console.Out, i, ns); this works great in creating the xml file with no namespace attributes. i would like to also have no encoding attribute in the root element, but I cannot find a way to do it. Does anyone have any idea if this can be done? Thanks Old answer removed and update with new solution: Assuming that it's ok to remove the xml declaration completly, because it makes not much sense without the encoding

Using generics with XmlSerializer

雨燕双飞 提交于 2019-12-02 23:13:10
When using XML serialization in C#, I use code like this: public MyObject LoadData() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyObject)); using (TextReader reader = new StreamReader(settingsFileName)) { return (MyObject)xmlSerializer.Deserialize(reader); } } (and similar code for deserialization). It requires casting and is not really nice. Is there a way, directly in .NET Framework, to use generics with serialization? That is to say to write something like: public MyObject LoadData() { // Generics here. XmlSerializer<MyObject> xmlSerializer = new XmlSerializer(); using

XmlSerializer and nullable attributes

◇◆丶佛笑我妖孽 提交于 2019-12-02 20:15:36
I have a class with numerous Nullable<T> 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 *Value and *Specified property as follows: [XmlIgnore] public int? Age { get { return this.age; } set { this.age = value; } } [XmlAttribute("Age")] public int AgeValue { get { return this.age.Value; } set { this.age = value; } } [XmlIgnore] public bool AgeValueSpecified { get { return this.age.HasValue; } } Which works fine - if the 'Age' property

How to avoid encoding of special characters in xmlroot

社会主义新天地 提交于 2019-12-02 18:41:14
问题 I trying to serialize a class JTDChanges with different xmlrootname "ns1:BatchChanges" but after serializing when I write it into a file, "ns1:BatchChanges" is encoded to "ns1_x003A_BatchChanges". This is my class [ Serializable, XmlRoot("ns1:BatchChanges") ] public class JTDChanges { [XmlElement("OrgUnitChanges")] public List<OrgUnitStage> CustomerChanges = new List<OrgUnitStage>(); } Can anyone please suggest how can I avoid the encoding? 回答1: I believe you are looking for the Xml Namespace