datacontractserializer

The deserializer has no knowlege of any type that maps to this contract

I'm trying to serialize and deserialize a tree of Node objects. My abstract "Node" class as well as other abstract and concrete classes that derive from it are defined in my "Informa" project. In addition, I've created a static class in Informa for serialization / deserialization. First I'm deconstructing my tree into a flat list of t...

RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected

Ok so I got DataContractSerializer working with my object graph. See my previous questions for more information. http://stackoverflow.com/questions/736568/serialization-derialization-of-a-tree-structure http://stackoverflow.com/questions/736900/the-deserializer-has-no-knowlege-of-any-type-that-maps-to-this-contract However, one of my ...

Formatting of XML created by DataContractSerializer

This isn't a big deal for me, but is there an easy way to get DataContractSerializer to spit out formatted XML rather then one long string? I don't want to change the tags or content in anyway just have it add line breaks and tabs to make the XML more readable? <tagA> <tagB>This is</tagB> <tagC>Much</tagC> <tagD> <tagE...

DataContractSerializer: How to serialize classes/members without DataContract/DataMember attributes

DataContractSerializer requires classes and members to be marked with the DataContract and DataMember attributes. However, in my case the classes are auto-generated with the EFPocoAdapater framework and these attributes are not present. How can I force serialization of all members using the DataContractSerializer without these attribut...

DataContractSerializer serialzing the same object more than once per request

I'm in the process of writing a WCF application which will be consumed by a Silverlight application. I have done most of the design work and I am now doing the implementation, which has made me come up with this question. Here's an example of something that exists in my application: [DataContract] class Person { [DataMember] pr...

Why can't I serialize an object using DataContractSerializer?

I'm trying to serialize a type using the DataContractSerializer and am getting the exception below. This isn't for an SOA service, but I would still like to use the DataContractSerializer if possible. I am using .Net 3.5 SP1. Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializatio...

WCF Inheritance/Polymorphism and Serialization

I have a class, ReportDef, which is a concrete class that I've decorated with [DataContract] and [DataMember] attributes as needed. ReportDef is in assembly A1 along with my ServiceContract, IReportService. I then have another class, UiReportDef, which derives from ReportDef and is in assembly A2. UiReportDef has no additional state t...

DataContractSerializer: why not remove members?

I was reading Microsoft's Best Practices: Data Contract Versioning, and they state: Do not remove data members in later versions, even if the IsRequired property was left at its default property of false in prior versions. Can anyone suggest any reason for this? They don't elaborate. Since they say it's fine to add data members in ...

Custom serialization using DataContractSerializer

I am having a look into using the DataContractSerializer and I'm having trouble getting the right output format. The DataContractSerializer serializes the following class [DataContract(Name = "response")] public class MyCollection<T> { [DataMember] public List<T> entry { get; set; } [DataMember] public int index { get; ...

Declaring Known Types for data contracts in different assemblies

I have a method in a WCF service which returns a complex type (myComplexResult), which includes as one of its members a List (Of Common.myBaseClass). I want this list to hold items which can variously be of type Foo.myClass1 and Bar.myClass2, both of which inherit from Common.myBaseClass. Note that all of these classes are defined in d...

Generic IPropertyChangedNotifier using Dynamic Proxy and wcf serialization problem

I have implemented a generic IPropertyChangedNotifier using castle dynamic proxy. Here I intercept setter call in Proxy objects so that i don't have to raise PropertyChanged event in setters of my domain objects. The purpose was to use these proxy objects to bind it UI in a silevrlight application. The Problem is serialization of prox...

WCF - Measuring approximate message sizes programmatically

Given a class: [DataContract] public sealed class ChangedField { [DataMember(Name="I")] public ushort FieldId { get; set; } [DataMember(Name="V")] public object Value { get; set; } } WireShark shows that, when sent via a WCF TCP binding, the encoding of the message is in binary (printable characters only, but you get the idea)...

DataContractSerializer doesn't call my constructor ??

I just realized something crazy, which I assumed to be completely impossible : when deserializing an object, the DataContractSerializer doesn't call the constructor ! Take this class, for instance : [DataContract] public class Book { public Book() { // breakpoint here } [DataMember(Order = 0)] public string Title {...

Why does WCF wrap request/response types in another XML element, and how to prevent this?

I have a simple echo service where I've defined one operation method and a pair of types for request/response: [ServiceContract(Name = "EchoService", Namespace = "http://example.com/services", SessionMode = SessionMode.NotAllowed)] public interface IEchoService { [OperationContract(IsOneWay = fals...

WCF DataContractSerializer doesn't pick up contract attributes... why not?

I have the following type which I use as a message contract in WCF: [MessageContract(IsWrapped = true, WrapperNamespace = "http://example.com/services", WrapperName = "EchoRequest")] public class EchoRequest { public EchoRequest() { } public EchoRequest(String value) { Value = valu...

Is it a good idea to cache DataContractSerializer instances?

I'm writing a windows service application that needs to serialize and deserialize XML documents repeatedly during its execution. As I need to serialize and deserialize generic types that are not known during compilation time (I don't know a priori how many types I need to serialize/deserialize) I'd like to know if it is a good idea do ke...

DataContractSerializer, KnownType and inheritance

I've read many articles about known types and i belive my example should work. But it doesn't. I'm getting the following exception on deserialization and don't understand why: Error in line 1 position 2. Expecting element 'A' from namespace 'http://schemas.datacontract.org/2004/07/ConsoleApplication2'.. Encountered 'Element' with name ...

How can I make DataContractJsonSerializer serialize an object as a string?

I have a struct in C# that wraps a guid. I'm using DataContractJsonSerializer to serialize an object containing an instance of that class. When I was using a guid directly, it was serialized as a plain string, but now it's serialized as a name/value pair. Here's an NUnit test and supporting code that demonstrates the problem: privat...

DataContractSerializer outputting XML with "field" appended to all elements and out of order

I'm new to creating WCF REST services - so please let me kwow if I'm doing things wrong here. I have a REST-based service developed using WCF, with the following DataContract defined: namespace Messaging { [DataContract(Name = "Email", Namespace = "")] public class Email { #region Fields private string s...

DataContractSerializer not Serializing member of class that inherits ISerializable

I have this class: using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace Grouping { [Serializable] public class Group<T> : HashSet<T> { public Group(string name) { this.name = name; } protected Group(){} protected Group(Serializati...