Menu
  • HOME
  • TAGS

De-serializing a flagged enum with a space results in SerializationException

c#,wcf,datacontractserializer

You can't use space in values because DataContractSerializer uses it and it is hardcoded. See the source and the post. But if you really want to use space between words, then use one of the listed solutions: The first way. Use other whitespace characters such as three-per-em space in values....

Wrap primitive type in C# json object serialization and data contract

c#,serialization,json.net,datacontractserializer

You can write a custom JsonConverter var json = @"{""SomeValue"":""x"",""SomeStringValue"":""y""}"; var obj = JsonConvert.DeserializeObject<SomeObject>(json); public class MyConverter : JsonConverter { public override bool CanConvert(Type objectType) { throw new NotImplementedException(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return new WrappedString((string)reader.Value); } public override void WriteJson(JsonWriter...

XML Deserialization Error - unexpected 'EndElement'

c#,xml,deserialization,xmlserializer,datacontractserializer

Your classes contain a mixture of data contract attributes and XmlSerializer attributes. I am going to assume you are using XmlSerializer because of the application of the attribute [XmlSerializerFormat]. In that case, you need to: Put back the XmlRoot attribute on matchset: [Serializable] [XmlSerializerFormat] [DataContract(Name = "matchset", Namespace = "urn:expasy:scanprosite")]...

why do we need to prevent Circular Object References

json.net,xmlserializer,datacontractserializer,serializer

If you would serialize this into JSON then you would get an infinite JSON-document because at the time the Serializer serializes the CTest object into JSON and he reaches the Other property this property is referenced by itself and the serializer starts with serializing this object. And so one. public...

DataContractSerializer cannot deserialize after namespace changed

c#,namespaces,datacontractserializer

I would personally change the data contract and then create a script that parses the previously saved xmls to add the namespace info. Quick and simple. Something like loading xmls as string and then calling: xmlstr=xmlstr.Replace("<Type1>", "<Type1 xmlns:Namespace=\"http://example.com\">"); Or maybe create two classes (one with the old namespace and one...

Write only stream - get written bytes count with DataContractSerializer

c#,stream,datacontractserializer

Sample implementation of a wrapper I've made: public class CountedStream : Stream { private readonly Stream stream; public CountedStream(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); this.stream = stream; } public long WrittenBytes { get; private set; } public override void Flush() { this.stream.Flush(); } public override int...

Why isn't the dataContractSerializer not resolving the System.ServiceModel.Dispatcher.NetDispatcherFaultException?

c#,xml,wcf,app-config,datacontractserializer

You could avoid the exception simply by increasing the value of maxStringContentLength. No need for behaviors.

“InvalidDataContractException: Type contains two members with same data member name” for no apparent reason

c#,.net,wcf,datacontractserializer,datacontract

I can't reproduce this, just in case - you copied 2 times FileSystemFileIdInformation structure at ProtectedFile contains types: I wrote simple serialization example and it works without any exceptions in both ways(seriaization and deserialization) - my only change is that I added constructors for readonly parameters, but it really doesn't...

WCF Service hosted in a Windows Service - Wrong / Expected Namespace

c#,xml,wcf,serialization,datacontractserializer

I didn't know that because I was using a Windows Service as a host, the XML file was saved to /windows rather than the local directory. The invalid namespace was from an old XML file that still existed in /windows/syswow64.

During OnSerializing, able to avoid default values based on reference object, OnDeserialized fails

c#,xml-serialization,datacontractserializer

From a quick run of the posted code, the thing that jumps out is that the sample xml code string you are running the deserialize against does not match the format of the serialized xml string. The output from serializing your instance gives: <Parent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MyTypeNamespace"> <Child> <Child /> <Child...

Public IDictionary member of ViewModel class will not serialize via DataContractSerializer

c#,windows-store-apps,datacontractserializer

If you change the setter of your DataDictionary property from 'private' to 'public', then it should work as expected

How do I deserialize a List as another List instead of a readonly T[]?

c#,datacontractserializer

Try using a DataContractSerializer(typeof(List<ITestObject>) so that it knows the concrete type

DataContractJsonSerializer fails on generic / polymorphic objects

c#,generics,datacontractserializer

After 36h of searching, I finally found the correct way. Instead of looking in the registered types in the assembly, I add a static initializer to all subclasses of Tree which register their type. Furthermore I have to add the generic parameter TValue to the list of known types (see...

Understanding the concept of 'serializing by reference'

c#,serialization,protobuf-net,datacontractserializer

Each call to write-object is a separate serialization context; the reference-tracking is not preserved between calls As long as you correctly identify previously seen values, it shouldn't get recursive, but a depth check can help avoid issues Correct, although you could attempt to recognise semantically identical value types if...

create soap message from Data Contract

xml,wcf,soap,datacontractserializer

If you just want a plain request for documentation or something you can use WCF tracing. Simple and generic soulution for all yours services. At your system.serviceModel <system.serviceModel> ... <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" /> </diagnostics> .... </system.serviceModel> and add system.diagnostics element <system.diagnostics> <switches> <add...

DataContract for different data structure

c#,datamapper,datacontractserializer

When dealing with different data sources it is often a good idea to have a separation in structure. This will help isolate issues with the different areas of the software when coding. In short, you may want to have better naming conventions for your mappers, and perhaps separate them by...

DataContractSerializer produces XML with no child nodes, preserves no data

c#,xml,serialization,datacontractserializer

You need to mark the properties you wish to serialize with the [DataMember] attribute. From the documentation for DataContractAttribute Apply the DataContractAttribute attribute to types (classes, structures, or enumerations) that are used in serialization and deserialization operations by the DataContractSerializer. You must also apply the DataMemberAttribute to any field, property,...