• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 977
  • Last Modified:

OnDeserialized shows private members not populated

Folks,

I'm serializing a class to disk (using BinaryFormatter), and then deserializing.  Pretty straight-forward stuff.  When I deserialize and inspect my object in debugger (VS) I see that my private members are populated just fine.  However, If I add an OnDeserialized attributed method and use the debugger after calling Deserialize() I find that the private members aren't populated yet.  What gives?  I thought OnDeserialized is called AFTER the object is deserialized (and thus members should be available).  In my case, I'm finding that they are available AFTER OnDeserialized, which doesn't make sense.  What am I doing wrong?
0
sfun28
Asked:
sfun28
  • 3
  • 2
1 Solution
 
lazyberezovskyCommented:
You are definitely doing something wrong. Set breakpoint inside method marked with [OnDeserialized] attribute e.g.

[OnDeserialized]
private void RunThisMethod(StreamingContext context)
{     // Set breakpoint here
}

You'll see that this method called inside Deserialize. And values of members, not marked with [NonSerialized] attribute will be already filled in.
0
 
Roshan DavisCommented:
Can you use it wit hthe bracket on (OnDeserialized() or OnDeserializedAttribute())
eg.

[OnDeserializedAttribute()]
private void RunThisMethod(StreamingContext context)
{ 
    // 
}

OR

[OnDeserialized]
private void RunThisMethod(StreamingContext context)
{     
      //
} 

Open in new window

0
 
Roshan DavisCommented:
oops
[OnDeserialized()]
private void RunThisMethod(StreamingContext context)
{     
      //
} 

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sfun28Author Commented:
lazyberezovsky - that's exactly what I'm doing.  The breakpoint is how I discovered that the private member isn't being populated.  After the method exists and I return to the method that originally called DeSerialize and I inspect the object, the private member is populated.
0
 
sfun28Author Commented:
roshmon - I don't understand your suggestion.  As I've mentioned, I'm already doing what you posted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now