datacontractserializer

Custom attribute to switch property serialization to NetDataContractSerializer

In .NET 3.5, I would like to create a custom attribute (say [NetDataMember]) that would switch the serialization behavior from DataContractSerializer to NetDataContractSerializer. Basically, for a class A as illustrated below [DataContract] class A { [DataMember] public int SimpleProperty { get; set; } [Transcient] public IBar...

Apply IOperationBehavior override for plain serialization? (not service)

I would like to create an [CustomDataMember] attribute that override the formatter behavior of DataContractSerializer through an IOperationBehavior. I have followed the instructions given by Aaron Skonnard but when I call the DCS serializer, the custom behavior does not get neither instantiated nor called. Obviously, I am missing somet...

How to generate classes from schema for DataContractSerializer

Is there an equivalent tool to xsd.exe that will generate classes from schema but for use with the DataContractSerializer rather than XmlSerializer? ...

C# - what attributes to use to support serializing using both XMLSerializer and DataContractSerializer?

I have some simple POCO object: public class ProductCategoryDTO { public string Name { get; set; } public DateTime ModifiedDate { get; set; } } As sometimes field order is important (for example, if sending to Infopath forms), I need to keep element order when serializing. And now I am confused, what attributes I shou...

Is there a way to make DataContractSerializer output cleaner XML?

Using the DataContractSerializer to serialize my object I get an output similar to <?xml version="1.0" encoding="utf-8" ?> <AgentNotification xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/The.name.space.Notifications"&gt; <_x003C_Created_x003E_k__BackingField i:nil="true" xmlns="...

.NET / Silverlight: DataContractSerializer Byte Array and Sockets: Unexpected EOF deserializing.

Hello I am currently using sockets to try and send messages between a Silverlight 3 client and a .NET3.5 service. I can set up the TCP connection fine, and send data across, but my issue comes with serialising and deserialising DataContracts. Currently we are using WCF PollingDuplex binding to do this work, but we are not happy with i...

DataContractSerializer leaking memory untill process die

Hi guys! I have a .net4 application using EF4, I Expose my model through WCF using BasicHttpBinding (but this can be changed) that every time I try invoke this method my web server process start to grow in memory and the process die. The problem is when the DataContractSeralizer trying to serialize my Entity (has some relationships) ...

XSLT: Using parent node's namespace

I would like to avoid producing a repeated namespace in my XSLT output. (I am using XSLT to massage some XML so that Microsoft's DataContractSerializer sees fit to actually process it properly. One of the things that the DCS doesn't seem to like is defining the same namespace multiple times.) I am taking all of the "Characteristics" el...

wcf deserialize enum as string

I'm trying to consume a RESTful web service using WCF. I have no control over the format of the web service, so I have to make a few workarounds here and there. One major problem I cannot seem to get around, however, is how to make WCF deserialize an enum as a string. This is my code (names changed, obviously): [DataContract] public en...

DataContract Serialization - Base class property names not working.

I have a base class like the following: [Serializable] public class SerializableDomainObject<T> { public SerializableDomainObject() { ID = Guid.NewGuid(); } [DataMember(Name="ID", Order = 0)] public Guid ID { get; private set; } public void Save() { // serialize } public void Load()...

How to make DataContractSerializer safer?

I'm ran into a scenario recently where one of our devs added an object to our data contract that was not marked as a data member. We are using using the DataContractSerializer to store a configuration file for a piece of hardware we are controlling. The serialize operation did not succeed, obviously. The major problem this uncovered w...

Does Order Matter in the XML Read by the DataContractSerializer?

I have the following code: [DataContract(Namespace = "")] public class User { [DataMember] public string UserName { get; set; } [DataMember] public string FullName { get; set; } } //Deserialization test public void Test() { //CASE 1. //string xml = "<User><UserName>john</UserName>" + // "<Ful...

Generic WCF JSON Deserialization

I am a bit new to WCF and will try to clearly describe what I am trying to do. I have a WCF webservice that uses JSON requests. I am doing fine sending/receiving JSON for the most part. For example, the following code works well and as expected. JSON sent: { "guy": {"FirstName":"Dave"} } WCF: [DataContract] public class S...

Trouble with deserialization in mono

Anyone have any idea why the following XML generated by a data contract serializer in C# works just fine in Windows but not under Linux on Mono? The XML: <Message i:type="UserMessage" xmlns="http://schemas.datacontract.org/2004/07/NetTunnel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;type&gt;UserMessage&lt;/type&gt; <ni...

Passing an instance of anonymous type over WCF

I have a WCF service method that expects an object and then retrieves its properties using reflection. On the client side I create an anonymous type object var obj = new {FirstName="John", LastName="Doe"} and pass it to the method. I'm getting an exception: Type '<>f__AnonymousType0`2[System.String,System.String]' cannot be serial...

WCF chokes on properties with no "set ". Any workaround?

I have some class that I'm passing as a result of a service method, and that class has a get-only property: [DataContract] public class ErrorBase { [DataMember] public virtual string Message { get { return ""; } } } I'm getting an exception on service side: System.Runtime.Serialization.InvalidDataContractException: No set method...

WCF - probem with serializing inherited types

I have these classes: [DataContract] public class ErrorBase {} [DataContract] public class FileMissingError: ErrorBase {} [DataContract] public class ResponseFileInquiry { [DataMember] public List<ErrorBase> errors {get;set;}; } An instance of the class ResponseFileInquiry is what my service method returns to the client. Now, if...

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

Does datacontract serialization uses reflection?

XmlSerialization creates a serializer proxy for each class. The proxy resides in a different assembly so it can serialize only public fields. DataContract serialization can serialize private fields too. Does it mean it uses reflection? Isn't it slower than using a proxy (except for the first time)? ...

Really bizzare WCF DataContractSerializer behavior, did I find a bug?

I have a straight forward service like: [ServiceContract] public interface IService { [WebGet(UriTemplate = "/", ResponseFormat = WebMessageFormat.Xml)] [OperationContract] List<DataContracts.MyThing> Get(); } My datacontract is straightfoward, nothing unusual there: [DataContract] public class MyThing...