datacontractserializer

C# DataContractSerializer SerializationException with Enum set in object field

…衆ロ難τιáo~ 提交于 2019-12-08 06:25:12
问题 Given the following code, [DataContract] public class TestClass { [DataMember] public object _TestVariable; public TestClass(object value) { _TestVariable = value; } public void Save() { using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(new FileStream("test.tmp", FileMode.Create))) { DataContractSerializer ser = new DataContractSerializer(typeof(TestClass)); ser.WriteObject(writer, this); } } } public enum MyEnum { One, Two, Three } Why does it fail to serialize when

How to use interface data type without attribute “KnownType” in WCF?

青春壹個敷衍的年華 提交于 2019-12-08 04:09:33
问题 If I'm using "ServiceContract" that contains "OperationContract" operations. The operation return or received interface parameters. When I'm using the service I get an exception message: "The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to '{%className%}' to the list of known types". I can add the attribute of KnowTypes to the interface but my interface project is

Nested [DataContract]'s not serialising through WCF

本小妞迷上赌 提交于 2019-12-08 02:43:29
I'm having an issue where a class decorated with the [DataContract] attribute and appropriate [DataMember] attributes on properties is not serialising nested [DataContract] classes. This is the class i'm trying to serialise: [DataContract(Namespace = "http://foo.bar.com.au")] [KnownType(typeof(Point))] [KnownType(typeof(Site))] public sealed class Alarm : IExtensibleDataObject { [DataMember] public Point SourcePoint { get; set; } [DataMember] public Site SourceSite { get; set; } [DataMember] public DateTime ActiveTime { get; set; } [DataMember] public int Priority { get; set; } [DataMember]

Using the WCF DataContractJsonSerializer in .NET 3.5

人走茶凉 提交于 2019-12-08 00:35:28
问题 I'm trying to use the geocoding code from here in my ASP.NET MVC 2 site. Unfortunately, some of that code, specifically the DataContractJsonSerializer usage, is only possible through .NET 4.0 . As my hosting provider doesn't support .NET 4, I'm forced to implement that functionality in .NET 3.5. How can I rework the code (which I have reposted below) to work in .NET 3.5? The Google Maps Geocoding API can also return XML, if that's easier to serialize in 3.5... Below is the code I'm trying to

Forcing ASMX proxy to use XmlSerializer instead of DataContractSerializer

一世执手 提交于 2019-12-07 12:46:17
问题 We were given external SOAP services that we have to consume in our project. All of these provide WSDL data, but a lot of them are not .NET services (most of them were written in Java). We have generated a number of client proxies with wsdl.exe tool. This tool does what it's supposed to do, it creates proxies for us to consume. The problem appears once we try to call methods on these services using generated proxies. We intercept all SOAP requests for logging purposes and XML data looks

Avoiding using the “http://www.w3.org/2001/XMLSchema-instance” namespace with .Net DataContractSerializer

点点圈 提交于 2019-12-07 06:45:04
问题 I have a series of classes that I am converting to XML using .NET's DataContractSerializer in .NET 4.0. The serialisation is working fine, and I can parse the XML and recreate the .NET objects later without any difficulty. However, most of the DataMember's are not required. [DataMember(IsRequired = false)]. This works great on de-serializing the XML, where you can then just miss the XML node out of the document, but when serializing an exisiting object into XML, the DataContractSerializer

Data contract serialization with complex types

这一生的挚爱 提交于 2019-12-07 04:58:28
I am using Data Contract serialization to serialize the following classes in XML: [DataContract] public partial class Foo { [DataMember] public string MyString { get; set; } [DataMember] public int MyInt { get; set; } [DataMember] public Bar MyBar { get; set; } } [DataContract] public class Bar { public int BarId { get; set; } [DataMember] public string BarField { get; set; } } When I serialize it it generates XML like this: <Foo> <MyString>My text</MyString> <MyInt>2</MyInt> <MyBar> <BarField>My bar field</BarField> </MyBar> </Foo> What I would like to do is have the MyBar field not appear as

How to Customize Deserialization of a JSON enum in .NET?

此生再无相见时 提交于 2019-12-06 22:43:29
问题 I have the following sample C# code that is auto-genereated from an xsd using the svcutils.exe application. [DataContract] public enum Foo { [EnumMember(Value = "bar")] Bar = 1, [EnumMember(Value = "baz")] Baz = 2 } [DataContract] public class UNameIt { [DataMember(Name = "id")] public long Id { get; private set; } [DataMember(Name = "name")] public string Name { get; private set; } [DataMember(Name = "foo")] public Foo Foo { get; private set; } } The following is a unit test that attempts to

How to use interface data type without attribute “KnownType” in WCF?

南楼画角 提交于 2019-12-06 22:11:36
If I'm using "ServiceContract" that contains "OperationContract" operations. The operation return or received interface parameters. When I'm using the service I get an exception message: "The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to '{%className%}' to the list of known types". I can add the attribute of KnowTypes to the interface but my interface project is separated from the implementation project and they cannot have circular dependency reference so it's not

Can DataContractJsonSerializer handle cyclic references?

大憨熊 提交于 2019-12-06 16:01:19
Are there any serialization/deserialization scenarios that DataContractSerializer can handle, while DataContractJsonSerializer can't ? In particular, I am thinking of circular references: this MSDN page explains how circular references can be managed by DataContractSerializer via the use of IsReference = true in the DataContractAttribute constructor. On the other hand, the DataContractAttribute.IsReference documentation does not explicitly state that its applicability is limited to DataContractSerializer . Will DataContractJsonSerializer also honor the IsReference property? There's nothing