datacontractserializer

C# Serializing datacontracts from file

China☆狼群 提交于 2019-12-23 13:18:07
问题 I have a list of Xml messages specifically DataContract messages that i record to a file. And i am trying to deserialize them from file one by one. I do not want to read the whole file into memory at once because i expect it to be very big. I have an implementation of this serialization and that works. I did this by serializing using a FileStream and reading the bytes and using regular expression to determine the end of element. Then taking the element and using DataContractSerializer to get

Why is DataContractSerializer to StringWriter truncated?

。_饼干妹妹 提交于 2019-12-23 10:59:05
问题 I am using the DataContractSerializer to serialize EF4 objects to xml if there are exceptions. In my debug log i can see want was the data-content when something went wrong. I have two versions of code: one version that serializes to a file and one that serializes to a string using StringWriter . When serializing big items to file i get valid xml of about 16kb. when serializing the same item to string the xml is truncated after 12kb. Any idea what caused the truncation? ... var entity = ....

Maximum number of items that can be serialized or deserialized in an object graph… with knowtypes

跟風遠走 提交于 2019-12-23 09:33:26
问题 In a WCF 4.0 service we receive a huge amount of data in a generic list. This list object graph is bigger than the 65536 default limit. We are quite used to it, so we have configured the service for being able to getting those big graphs. <serviceBehaviors> <behavior> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> With the above chunk of xml config we have avoided the problem in the past with no problem, but now it doesn't work. The only

Can I serialize Dictionary<string, object> using DataContract serializer?

隐身守侯 提交于 2019-12-23 07:29:11
问题 I'm planning to build a WCFservice that returns generic dictionary objects serialized to JSON. Unfortunately, serialization fails, as object is potentially always different. KnownTypes can't help, because property type is Dictionary, and I can't say KnownType, as the class will potentially be always different. Any ideas if it's possible to serialize an 'unknown type'? I don't mind to specify DataContract/DataMember for each of my classes, but (at least for prototype version) I don't want to

Data contract serialization with complex types

喜欢而已 提交于 2019-12-23 03:50:24
问题 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>

Ignore some properties in runtime when using DataContractSerializer

扶醉桌前 提交于 2019-12-22 04:45:12
问题 I am using DataContractSerializer to serialize an object to XML using DataMember attribute (only public properties are serialized). Is it possible to dynamically ignore some properties so that they won't be included in the XML output? For example, to allow user to select desired xml elements in some list control and then to serialize only those elements user selected excluding all that are not selected. Thanks 回答1: For the list scenario, maybe just have a different property, so instead of:

When using ISerializable with DataContractSerializer, how do I stop the serializer from outputting type information?

China☆狼群 提交于 2019-12-22 03:22:27
问题 To get more control over serialization, I have converted a class from [DataContract] to [Serializable], implementing both GetObjectData and the special deserializing constructor. When I do this, the XML emitted now has type information applied to all elements. I don't want this superfluous information, and I'm wondering how to inform the serializer to not output it. Here's the sample code that uses [DataContract]: [DataContract(Namespace = "")] class Test { public Test() { } [DataMember]

Object hierarchy returned by WCF Service is different than expected

你说的曾经没有我的故事 提交于 2019-12-21 21:27:44
问题 My understanding may be wrong, but I thought once you applied the correct attributes the DataContractSerializer would render fully-qualified instances back to the caller. The code runs and the objects return. But oddly enough, once I look at the returned objects I noticed the namespacing disappeared and the object-hierarchy being exposed through the (web applications) service reference seems to become "flat" (somehow). Now, I expect this from a web-service…but not through WCF. Of course, my

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

情到浓时终转凉″ 提交于 2019-12-21 12:45:20
问题 Ok so I got DataContractSerializer working with my object graph. See my previous questions for more information. Serialization / Derialization of a tree structure The deserializer has no knowlege of any type that maps to this contract However, one of my fields, _UserPropertyDefinitions , is defined as shown below.. It defines a list of custom properties that this user can add to objects in the data structure. The string is a unique key to identify the property, and Type is the type of the

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

坚强是说给别人听的谎言 提交于 2019-12-21 12:45:11
问题 Ok so I got DataContractSerializer working with my object graph. See my previous questions for more information. Serialization / Derialization of a tree structure The deserializer has no knowlege of any type that maps to this contract However, one of my fields, _UserPropertyDefinitions , is defined as shown below.. It defines a list of custom properties that this user can add to objects in the data structure. The string is a unique key to identify the property, and Type is the type of the