datacontractserializer

How to customize dictionary serialization with DataContractSerializer?

狂风中的少年 提交于 2020-07-22 22:11:17
问题 Dictionary serialization with DataContractSerializer generate below data. How to replace d2p1:KeyValueOfintint , d2p1:Key and d2p1:Value with our own attributes / tags / identifier. Serializing Dictionary in [CashCounter], Output Generate after Serialization given below <CashCounter xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DictionarySerlization"> <BankNote xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d2p1

WCF Service Reference - Getting “XmlException: Name cannot begin with the '<' character, hexadecimal value 0x3C” on Client Side

本秂侑毒 提交于 2020-02-17 11:24:28
问题 I have a smart client application communicating with its server via WCF. Data is created on the client and then sent over the service to be persisted. The server and client use the same domain classes via a shared dll and I'm using the handy "Add Service Reference" functionality in Visual Studio that wraps SvcUtil.exe and generates the client and proxy classes. I get the following error when trying to call the service: System.Xml.XmlException occurred Message=Name cannot begin with the '<'

Renaming of class property that is marked with a DataMemberAttribute

老子叫甜甜 提交于 2020-01-30 07:53:07
问题 Actually i have a class like this [DataContract] public class Item : IExtensibleDataObject { [Browsable(false)] public virtual ExtensionDataObject ExtensionData { get; set; } [DataMember] public string ID { get; set; } [DataMember] public string Name { get; set; } public Item() : this(String.Empty, String.Empty) { } public Item(string id, string name) { ID = id ?? String.Empty; Name = name ?? String.Empty; } } You can easily serialize and deserialize it. But now comes the hard part: I have to

DataContract not able to serialize collection members

两盒软妹~` 提交于 2020-01-30 05:26:13
问题 I have data that is best described as "onion-like" in that each outer layer builds on the one below it. Below you will see a vastly simplified version (mine is several layers deeper but exhibits the same behavior at each level). [CollectionDataContract] public abstract class AbstractTestGroup : ObservableCollection<AbstractTest> { [DataMember] public abstract string Name { get; set; } } [CollectionDataContract] [KnownType(typeof(Test))] public class TestGroup : AbstractTestGroup { public

Default Values For Missing Data Members In DataContractSerializer

你离开我真会死。 提交于 2020-01-14 12:18:51
问题 With the below two data members in a DataContract then using a DataContractSerializer, only Name is serialized as expected. My problem is when I deserialize the file. "Name" is read and loaded properly but as "Timeout" does not exist I would expect it to stay at the default of "TimeSpan.FromHours(12)". What infact happens is the DataContractSerializer assigns a value but as it has no value to assign it uses the timespan default of 0. Is there anyway around this behavour? private string _name;

How can I control the root element namespace and name when serializing an IXmlSerializable object with the data contract serializer?

懵懂的女人 提交于 2020-01-09 11:49:26
问题 I have a type that implements IXmlSerializable which I am serializing with DataContractSerializer. How can I control the root element namespace and name when serializing it as the root element of an XML document? Say I have the following type: public partial class PersonDTO : IXmlSerializable { public string Name { get; set; } #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { return null; } public void ReadXml(System.Xml.XmlReader reader) { Name = reader["name"

Best way to store serialization related info between serialization and deserialization

╄→尐↘猪︶ㄣ 提交于 2020-01-06 14:59:51
问题 I'm using serialization with DataContractSerializer and have to save e.g. object which has field of Dictionary<string, IKnownTypesProvider> where IKnownTypesProvider just know which types does it consist from. So I can easily use it to serialize existing object. But if I want to deserialize it later I have to pass a list of known types to DataContractSerializer but I can't do it because I don't know which types were used when that object was serialized. All synthetic samples from MSDN

Best way to store serialization related info between serialization and deserialization

China☆狼群 提交于 2020-01-06 14:59:24
问题 I'm using serialization with DataContractSerializer and have to save e.g. object which has field of Dictionary<string, IKnownTypesProvider> where IKnownTypesProvider just know which types does it consist from. So I can easily use it to serialize existing object. But if I want to deserialize it later I have to pass a list of known types to DataContractSerializer but I can't do it because I don't know which types were used when that object was serialized. All synthetic samples from MSDN

SecurityException when serializing with DataContractSerializer

柔情痞子 提交于 2020-01-05 04:58:26
问题 I'm trying to serialize the state of my game on Windows Phone 7, and so made a "Save" struct so I could easily convert all the states into an XML doc using DataContractSerializer. The Save() code worked fine when I just serialized each data member of the Gamestate individually. However this led to a multiple xml root error, so I made the "Save" class to act as the sole root. Now I get a security exception whenever I try and call DataContractSerializer.WriteObject() on anything. I've been