datacontractserializer

Trouble with DataContractSerializer

∥☆過路亽.° 提交于 2019-12-11 20:18:34
问题 I'm trying to make DataContract Serializer work with one of my class. Here it is : public class MyOwnObservableCollection<T> : ObservableCollection<T>, IDisposable where T : IObjectWithChangeTracker, INotifyPropertyChanged { protected List<T> removedItems; [DataMember] public List<T> RemovedItems { get { return this.removedItems;} set { this.removedItems = value;} } // Other code removed for simplification // ... // } It is important to understand that the RemovedItems list gets populated

Why can't I deserialize my object if the xml it contains gets slightly larger?

有些话、适合烂在心里 提交于 2019-12-11 12:52:24
问题 I am having an issue trying to send a message to the Azure service bus using the REST API and have it received using the .NET azure service bus client API classes. I can happily send and receive messages using these objects using the SDK alone, but get problems when trying to use the REST api. I have narrowed the issue down to this minimal repro I think. Basically if I serialize my object with a small amoutn of XML as the payload thee everything works ok. If I add slightly more XML then I get

Trying to deserialize JSON using JSON.NET and DataContractJsonSerializer fails

廉价感情. 提交于 2019-12-11 09:36:45
问题 plz help, I'm stuck. I have a WCF service which returns something like this: { "GetDataRESTResult": [ {"Key1":100.0000,"Key2":1,"Key3":"Min"}, {"Key1":100.0000,"Key2":2,"Key3":"Max"} ] } and I would like to deserialize it, but whatever I use (JSON.NET or DataContractJsonSerializer) I'm getting errors. When using DataContractJsonSerializer I'm using theis code: byte[] data = Encoding.UTF8.GetBytes(e.Result); MemoryStream memStream = new MemoryStream(data); DataContractJsonSerializer serializer

ServiceStack.Text: Forcing serialization of a property not decorated with DataMember attribute

…衆ロ難τιáo~ 提交于 2019-12-11 06:27:32
问题 I have the following class (simplified). [DataContract] public class ServiceResponse { public int Sequence { get; set; } [DataMember] public ServiceResponseStatus Status { get; set; } } I'm using ServiceStack to serialize objects for logging purposes, and letting DataContractSerializer do the rest. ServiceStack, as expected, will not serialize Sequence as it is not decorated with a DataMember attribute. Is there a way to force ServiceStack to serialize this property? Marc Gravell's answer to

Svcutil generates wrong Name property value in DataContractAttribute

爷,独闯天下 提交于 2019-12-11 04:39:42
问题 When I use svcutil.exe to generate a Customer class from the definition contained in the xsd file: <xs:schema ...> <xs:element name="customer" type="Customer" nillable="true" /> <xs:complexType name="Customer"> <xs:sequence> <xs:element name="id" type="xs:decimal" minOccurs="0" /> <xs:element name="first_name" type="xs:string" /> <xs:element name="last_name" type="xs:string" /> <xs:element name="phone" type="Phone" minOccurs="0" /> <xs:element name="email" type="Email" minOccurs="0" /> <xs

C# Entity Framework lazy loading if not detached

痴心易碎 提交于 2019-12-11 04:26:01
问题 I am trying to do some process against every object in my EntityFramework OnSave. Part of this process involves turning the object into a Binary object. It is taking FOREVER to Serialize and I am about 99% positive that it is because we are using Lazy Loading on our EntityFramework and it is grabbing Lazy Loaded objects that are accessed in PartialClasses. I tried detaching my object from the ObjectContext, but my coworkers have used Lazy Loading all over our application without first

Silverlight 4 and System.Runtime.Serialization

允我心安 提交于 2019-12-11 03:17:29
问题 I have a Silverlight 4 project that contains some business objects. I added a Test project. One of the tests is to serialize the business objects from the Silverlight project using DataContractSerializer . To reference DataContractAttribute , I have to add a reference to System.Runtime.Serialization . However, there are different and apparently incompatible versions in the Silverlight runtime and in the .NET 4 Runtime of the Test project. What's the best strategy to serialize objects in a

DataContract surrogate for amplified value type

末鹿安然 提交于 2019-12-11 03:08:32
问题 I want to use a custom aplified type (think Nullable) in a DataContract class. I tried to write a IDataContractSurrogate but it fails at deserialization. My amplified type looks like this: public struct Amplified<TValue> { public TValue Value { get; set; } //... some special code ... } And a DataContract may look like this: [DataContract] public class MyDTO { [DataMember] public Amplified<string> SpecialString { get; set; } } The above code works but produces unnecessary nesting with the

DataContractSerializer to deserialize a Member without namespace?

会有一股神秘感。 提交于 2019-12-11 02:17:16
问题 I need to deserialize this xml (that I can't change): <foo:a xmlns:foo="http://example.com"> <b>string</b> </foo:a> I made this class: [DataContract(Name = "a", Namespace = "http://example.com")] public class A { [DataMember(Name = "b", Order = 0)] public string B; } And I did: using (var streamObject = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { var ser = new DataContractSerializer(typeof(A)); return (A)ser.ReadObject(streamObject); } I get an object of class A, but the content of B is

Change XML Namespace of DataMember

醉酒当歌 提交于 2019-12-11 01:02:36
问题 I have two DataContract s which I am serializing to XML using a DataContractSerializer . I specify different namespace for the two different DataContract s however, there is a DataMember in each DataContract which is of the same POD type. This POD is in a different c# namespace. I would like to know if there is a way of specifying the namespace to use for this DataMember depending on which containing type it belongs to. For example: namespace NamespaceShared { using System.Runtime