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?
LVL 1
sfun28Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.