xmlserializer

Why doesn't XmlSerializer support Dictionary?

本小妞迷上赌 提交于 2019-11-26 06:47:33
问题 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 difficult for a XmlSerializer to deal with considering it\'s really an array of KeyValuePairs. In fact, you can pass an IDictionary<TKey, TItem> to a method expecting an IEnumerable<KeyValuePairs<TKey, ITem>> . 回答1: Hashtables need hashcode and

WCF Error “Maximum number of items that can be serialized or deserialized in an object graph is &#39;65536&#39;”

淺唱寂寞╮ 提交于 2019-11-26 04:55:43
问题 I am receiving the following error on a WCF call: Maximum number of items that can be serialized or deserialized in an object graph is \'65536\' I\'ve read a ton of forum posts and many of them mention modifying the app.config and web.config to specify new behavior to allow larger object graphs. I\'ve done that and this is what I have in those files: App.Config on the WPF project: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=\"\"> <serviceMetadata httpGetEnabled=\"false

XML Serialization and namespace prefixes

别说谁变了你拦得住时间么 提交于 2019-11-26 04:45:30
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 DataContractSerializer and the XmlSerializer I can add a namespace, but they seem to generate a prefix internally, with something that I'm not able to control. Am I able to control it with either of these serializers (I can use either of them)? If I'm not able to control the

ShouldSerialize*() vs *Specified Conditional Serialization Pattern

℡╲_俬逩灬. 提交于 2019-11-26 03:27:00
问题 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 conditionally? This question is specific to the usage of XmlSerializer , but general information regarding this topic is welcome as well. There is very little information on this topic out there, so it may be because they perform the exact same purpose and

XML Serialization and namespace prefixes

扶醉桌前 提交于 2019-11-26 03:25:21
问题 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 DataContractSerializer and the XmlSerializer I can add a namespace, but they seem to generate a prefix internally, with something that I\'m not able to control. Am I able

Deserialize XML To Object using Dynamic

点点圈 提交于 2019-11-26 02:51:21
问题 Is it possible Deserialize unknown XML to object like below? var xml = @\"<Students><Student><Name>Arul</Name><Mark>90</Mark></Student></Students>\"; var serializer = new XmlSerializer(typeof(DynamicObject)); dynamic students = serializer.Deserialize(new XmlTextReader(new StringReader(xml))); 回答1: You may want to try this. string xml = @"<Students> <Student ID=""100""> <Name>Arul</Name> <Mark>90</Mark> </Student> <Student> <Name>Arul2</Name> <Mark>80</Mark> </Student> </Students>"; dynamic

Memory Leak using StreamReader and XmlSerializer

只谈情不闲聊 提交于 2019-11-26 00:08:57
问题 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) { StreamReader r = new StreamReader(@\"C:\\Program Files\\\" + sym + \".xml\"); XmlSerializer xml = new XmlSerializer(typeof(XMLObj), new XmlRootAttribute(\"rootNode\")); XMLObj obj = (XMLObj)xml.Deserialize(r); obj.Dispose(); r.Dispose(); r.Close(); } } catch