Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 803099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:42:17+00:00 2026-05-14T23:42:17+00:00

I have a problem which I have been bashing my head against for the

  • 0

I have a problem which I have been bashing my head against for the better part of three hours. I am almost certain that I’ve missed something blindingly obvious…

I have a simple XML file:

<?xml version="1.0" encoding="utf-8"?>
<WeightStore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
  <Records>
    <Record actual="150" date="2010-05-01T00:00:00" />
    <Record actual="155" date="2010-05-02T00:00:00" />
  </Records>
</WeightStore>

I have a simple class structure:

[Serializable]
public class Record
{
    [XmlAttribute("actual")] public double weight { get; set; }
    [XmlAttribute("date")]   public DateTime date { get; set; }
    [XmlIgnore]              public double trend { get; set; }
}

[Serializable]
[XmlRoot("WeightStore")]
public class SimpleWeightStore
{
    [XmlArrayAttribute("Records")]
    private List<Record> records = new List<Record>();
    public List<Record> Records { get { return records; } }

    [OnDeserialized()]
    public void OnDeserialized_Method(StreamingContext context)
    {
        // This code never gets called
        Console.WriteLine("OnDeserialized");
    }
}

I am using these in both calling code and in the class files:

using System.Xml.Serialization;
using System.Runtime.Serialization;

I have some calling code:

SimpleWeightStore weight_store_reload = new SimpleWeightStore();
TextReader reader = new StringReader(xml);
XmlSerializer deserializer = new XmlSerializer(weight_store.GetType());
weight_store_reload = (SimpleWeightStore)deserializer.Deserialize(reader);

The problem is that I am expecting OnDeserialized_Method to get called, and it isn’t.

I suspect it might have something to do with the fact that it’s XML deserialization rather than Runtime deserialization, and perhaps I am using the wrong attribute name, but I can’t find out what it might be.

Any ideas, folks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:42:17+00:00Added an answer on May 14, 2026 at 11:42 pm

    There’s no equivalent of OnDeserialized for XML deserialization.

    See this post for workarounds: How do you find out when you've been loaded via XML Serialization?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem which I've simplified down and have been scratching my head
I have a problem which has been torturing for many hours. I need to
I have problem with regex. I've been playing with it for three hours and
So I have a rather basic javascript problem which I have been slamming my
I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
I have a code problem which stems from the fact that I am using
I have a strange problem which I have been trying to fix for some
I have a problem, I have a .dotx file which has been supplied by
I have an interesting problem which I've been looking into and would appreciate some
The root problem: I have an application which has been running for several months

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.