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

  • SEARCH
  • Home
  • 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 6663871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:32:50+00:00 2026-05-26T02:32:50+00:00

I serialize an XML file into an object using the built-in .NET functionality (XmlSerializer.Deserialize).

  • 0

I serialize an XML file into an object using the built-in .NET functionality (XmlSerializer.Deserialize). After the object’s fields have been set, I want to act on that data by calling additional code in the object’s constructor. Unfortunately, stepping through the code reveals that the “additional” code is executed first before the serialization logic is executed. That makes the approach unfeasible, since there fields haven’t been initialized yet and there’s no data to act on.

Is there a known solution to this problem? Up to now, I’ve always called a second method that does this initialization of data, but it’s clunky and prone to errors: it has to be called after each serialization (other programmers might not be aware of that), or I have to create another wrapper to load the object (and stuff starts spiraling).

  • 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-26T02:32:51+00:00Added an answer on May 26, 2026 at 2:32 am

    If a constructor is being invoked, it will always be the first thing (note that some serializers skip the constructor; XmlSerializer always runs a public parameterless constructor). As such, any logic will have to be in the properties etc.

    What you are really describing here is “serialization callback” – i.e. a way of getting the serializer to run a method of yours before and/or after serialization and/or deserialization; some serializers support callbacks – however, XmlSerializer does not.

    The only option with XmlSerializer is to implement IXmlSerializable, but frankly that is a huge pain. If possible, I would suggest either:

    • call a method manually, yourself, after deserialization
    • or, switch serializer to one that supports callbacks

    DataContractSerializer supports callbacks and can do limited xml – not as fine-grained control as XmlSerializer though (no attributes, in particular); protobuf-net supports callbacks if you want to switch to binary.

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

Sidebar

Related Questions

I have an XML file that I'm trying to serialize into an object. Some
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I'm using the built-in Java XML Transformer to serialize an XML document into text.
I have an XML file which I want to convert into JSON file using
I want to Serialize a 60mb file into XML but it gives me System
I have an object I can serialize to XML without a problem. However when
I were using FileStream to Serialize an Object to Xml and Save to the
Basically, I have a class with 2 methods: one to serialize an object into
I have following code to serialize my data into a file: out = new
I have an XML File that I am processing using LINQ. I want to

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.