datacontractserializer

Is it possible to create a DataContract with XmlText content so that it serializes correctly?

Is it possible to represent this format using Data Contract Serialization? <Person id="123">Ted</Person> ...

Can I control what subtype to use when deserializing a JSON string?

I'm working with Facebook API and it's search method returns a JSON response like this: { "data": [ { "id": "1", "message": "Heck of a babysitter...", "name": "Baby eating a watermelon", "type": "video" }, { "id": "2", "message": "Great Produce Deals", "...

C# - Serializing and Deserializing Linq Tables whilst maintaining Relationships

Hi All, I want to Test my code! A noble goal I'm sure you agree. I need to mock out DataContexts for my Regression tests, running the test will verify that for any code change, given the same input we produce the same output. I'm using Moles to mock out my data contexts. It's awesome and simple, I recommend it, I might move to Moq if ...

How do I use DataContractSerializer to create nodes/elements for a containing XML file?

Say I am persisting some application data to a single XML file and I want to use the DataContractSerializer to create all or most of the elements. So my file might look like: <?xml version="1.0" encoding="utf-8"?> <Settings> <A ... /> <B ... /> </Settings> (A and B are serialized using DCS.) How would I go about writing this fil...

Renaming of class property that is marked with a DataMemberAttribute

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,...

Inconsistent type not expected serialization fault

Does anybody have any idea what could cause an inconsistent fault like: [FaultException1: Type 'System.Collections.ObjectModel.Collection1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not...

XmlSerializer vs DataContractSerializer

I just realized that DataContractSerializer expects nodes in the alphabetical order or the specified order. Is there any way i could make it NOT do it? TIA ...

Slightly non-trivial data structure: is XmlSerializer right for me?

I'm currently using XmlSerializer to, surprisingly enough :), handle de/serialization of my data structures - I find it wonderfully simple to use, but at the cost of flexibility. At the moment, I'm using it for a tree-based structure; since XmlSerializer doesn't handle cyclic structures, I've added [XmlIgnore] to my Parent property, and ...

Does the DataContractSerializer call property getters/setters?

I know that on deserialization the DataContractSerializer does not call the constructor. Does it also bypass a public or private property's setter method? ...

WCF method throws an exception of maximum items in an object graph is '65536'

I get an exception when there are too many objects returned: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://.../Contract:GetBlaBlaResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object ...

Cannot Serialize a List<> of DynamicProxy2-generated objects with DataContractJsonSerializer

I'm running into an issue using System.Runtime.Serialization.Json.DataContractJsonSerializer to serialize a List<T> of proxied objects. It works fine with a single proxied object, but the List makes it blow up. Something like this: using System.Collections.Generic; using System.Runtime.Serialization; using Castle.DynamicProxy; using ...

Control object creation during deserialization

I would like to control object creation of a type that is not usually serializable during deserialization using a NetDataContractSerializer (or any serializer I guess). Using a custom SerializationBinder I can control the type that is constructed and using a custom ISurrogateSelector and ISerializationSurrogate to control how state is se...

"ReadElementContentAsBase64 method is not supported on this XmlReader"

using System.IO; using System.Runtime.Serialization; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; namespace XmlTest { class TestClass : IXmlSerializable { public XmlSchema GetSchema() { return null; } public void ReadXml(XmlReader reader) { ...

C# Data Contract deserialisation returning 'null' for collection.

We're using DataContractSerializer to deserialise XML data coming into a RESTful API written in MVC.Net. I'm trying to send a list of objects into an action method, however the deserialisation always returns null, even when using XML serialised from the same classes. Does anyone have any idea's of why this is happening. Code is below. [...

How to ensure interoperability with DataContractSerializer when talking to non-.NET app?

Say I have a non-.NET app which needs to write data to be deserialized by a .NET app via DataContractSerializer. Where's the specification describing the exact format necessary? Such a spec should describe a lot of stuff, including: Does the order of sibling elements matter? Should the xml namespace URIs always begin with http://schem...

Error: "The deserializer has no knowledge of any type that maps to this contract" ?

I have a class Foo marked [Serializable] and implementing ISerializable. I'm trying to serialize it via DataContractSerializer. In GetObjectData I do this: info.AddValue("Test", new[] { 1,2,3}); It fails with: Element ':Test' contains data of the 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfint' data contract....

Events not working with after Deserialization

PROBLEM: I have a Child class which uses DataContractSerialization and raises a Changed event when its Name property is set. <DataContract()> Public Class Child Public Event Changed() <DataMember()> Private _Name As String Public Sub New(ByVal NewName As String) _Name = NewName End Sub Public Propert...

Stop DataContractSerializer putting in namespace?

I want to serialize datacontract classes into XMl, but without the Namespaces. I've added: [DataContract(Namespace="")] but I still get: <Person xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; <Title>Mr</Title> ... </Person> Is there any way to stop this happening as I just want the clean xml to pass into a legacy componen...

WCF Client having problems recognizing ServiceKnownTypes?

How would I tell the WCF service what KnownTypes to use when passing data back to the client? I know I can use the [ServiceKnownType] attribute, which makes the service call run fine from a WCF Test Server, however it still fails from the client. Am I missing something here? [OperationContract] [ServiceKnownType(typeof(SubClassA))] [Se...

Data Contract for a class with fields being user defined classes itself

I am Using WCF service to implement my web-service I have problem when I try to call my function which takes URL as input parameter and returns an object class which was defined by me. public class Service: IService<br> { public ClassWS My_Stores(String URL) { try { //ClassWS is a class which has othe...