iserializable

Problem deserializing with NetDataContractSerializer after refactoring code

纵然是瞬间 提交于 2020-02-27 07:26:18
问题 I have a situation where I'm serializing some .NET objects using NetDataContractSerializer and storing the XML in a database as a way to remember the state of these objects within an application. Recently I just came across the first situation where some code refactoring of property and type names has resulted in the failure to deserialize this XML data. So far I've come up with two different plans of attack for how to deal with version compatibility breaks such as these which are to use

Resolving Circular References for Objects Implementing ISerializable

随声附和 提交于 2019-12-22 09:57:15
问题 I'm writing my own IFormatter implementation and I cannot think of a way to resolve circular references between two types that both implement ISerializable. Here's the usual pattern: [Serializable] class Foo : ISerializable { private Bar m_bar; public Foo(Bar bar) { m_bar = bar; m_bar.Foo = this; } public Bar Bar { get { return m_bar; } } protected Foo(SerializationInfo info, StreamingContext context) { m_bar = (Bar)info.GetValue("1", typeof(Bar)); } public void GetObjectData

What's the difference between using the Serializable attribute & implementing ISerializable?

放肆的年华 提交于 2019-12-17 08:54:41
问题 What's the difference between using the Serializable attribute and implementing the ISerializable interface? 回答1: When you use the SerializableAttribute attribute you are putting an attribute on a field at compile-time in such a way that when at run-time, the serializing facilities will know what to serialize based on the attributes by performing reflection on the class/module/assembly type. [Serializable] public class MyFoo { … } The above indicates that the serializing facility should

How to implement ISerializable in F#

半城伤御伤魂 提交于 2019-12-12 19:22:56
问题 Let's say you start off with this stub: [<Serializable>] type Bounderizer = val mutable _boundRect : Rectangle new (boundRect : Rectangle) = { _boundRect = boundRect ; } new () = { _boundRect = Rectangle(0, 0, 1, 1); } new (info:SerializationInfo, context:StreamingContext) = { // to do } interface ISerializable with member this.GetObjectData(info, context) = if info = null then raise(ArgumentNullException("info")) info.AddValue("BoundRect", this._boundRect) // TODO - add BoundRect property

Passing recursive collection through WCF

三世轮回 提交于 2019-12-11 02:34:20
问题 I want to pass a fairly generic set of data through a WCF method. The data is basically just a hierarchical set of key/value pairs, but it's nested to an arbitrary level. I originally considered passing it though as a single string and doing XML or JSON or similar encoding/decoding at either end, but since the WCF transport is XML anyway that seemed a little silly, so I'm hoping there's a way to pass it through "naturally". The method is fairly straightforward: [OperationContract] void

Using WCF DataContract in MVC SessionState using AppFabric cache

帅比萌擦擦* 提交于 2019-12-09 06:30:21
问题 I have a Data Access Layer, a Service Layer, and a Presentation Layer. The Presentation Layer is ASP.NET MVC2 RTM (web), and the Service Layer is WCF (services). It's all .NET 3.5 SP1. The problem is that in the services, the objects being returned are marked with the [DataContract] attribute. The web is using the AppFabric Cache (a.k.a Velocity) SessionStateProvider to store session state. Due to this, anything I store in the session must be serializable. Here comes the problem: the

Cross-Process Drag and Drop of custom object type in WinForms C#

三世轮回 提交于 2019-12-06 22:43:06
问题 This question is close to what I'm interested in, but not quite. I have a .NET WinForms application written in C#. I have a ListView control which displays an array of C# objects. I've hooked it up so that you can drag/drop these listview items to a different form in the same application, and it properly passes the array of objects (type Session ) to the drop handler for that other form. However, I now want to support cross-process drag/drop where I run multiple instances of my application.

Resolving Circular References for Objects Implementing ISerializable

为君一笑 提交于 2019-12-05 22:02:36
I'm writing my own IFormatter implementation and I cannot think of a way to resolve circular references between two types that both implement ISerializable. Here's the usual pattern: [Serializable] class Foo : ISerializable { private Bar m_bar; public Foo(Bar bar) { m_bar = bar; m_bar.Foo = this; } public Bar Bar { get { return m_bar; } } protected Foo(SerializationInfo info, StreamingContext context) { m_bar = (Bar)info.GetValue("1", typeof(Bar)); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("1", m_bar); } } [Serializable] class Bar :

Deserialization of an array always gives an array of nulls

时光总嘲笑我的痴心妄想 提交于 2019-12-05 19:43:21
问题 I have a custom abstract base class with sub classes that I've made serializable/deseriablizeable with ISerializable. When I do serialization/deserialization of single instances of this class' sub classes, everything works fine. However, when I do an array of them I always end up with an array of nulls on deserialization. Serialization is done with BinaryFormatter. The items are contained within a: public ObservableCollection<Trade> Trades { get; private set; } On serialization this is done

Cross-Process Drag and Drop of custom object type in WinForms C#

假装没事ソ 提交于 2019-12-05 03:09:15
This question is close to what I'm interested in, but not quite. I have a .NET WinForms application written in C#. I have a ListView control which displays an array of C# objects. I've hooked it up so that you can drag/drop these listview items to a different form in the same application, and it properly passes the array of objects (type Session ) to the drop handler for that other form. However, I now want to support cross-process drag/drop where I run multiple instances of my application. This appears that it's going to work (e.g. GetDataPresent succeeds), but ultimately throws an exception