4

The ISerializable interface only provides a method to serialize the object. The deserialization process is managed by a constructor.

The problem is, that constructor cannot return an instance, because the constructor CREATES a new instance.

In my implementation, there are several attributes corresponding to singletons instantiated and maintainded somewhere else.

I need the deserialization process to get that instance and assign to the attribute, instead of creating a new instance.

The constructor approach is not suitable for this.

In Java, you would call the ReadResolve() method, is there a C# equivalent?

user1275011
  • 1,129
  • 1
  • 10
  • 28
  • Please don't prefix your titles with "C#" and such. That's what the tags are for. – John Saunders Apr 11 '12 at 19:30
  • @user1275011 I see you haven't ever accepted an answer. In all of the questions you've posted, if someone posts something you believe to be correct, then mark it so! – Osiris Apr 11 '12 at 20:17

1 Answers1

3

You need to make your classes which save a reference to the singleton implement IObjectReference.

Take a look at http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iobjectreference.aspx

Osiris
  • 469
  • 3
  • 13