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 7851823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:16:22+00:00 2026-06-02T19:16:22+00:00

The odd task that I have been given is to serialize a LARGE object

  • 0

The odd task that I have been given is to serialize a LARGE object using XML Serialization. This object contains multiple Nested UserDefined classes, with multiple DateTime fields. The Requirement for the DateTime data is that it must ALWAYS be displayed in the TimeZone of the user who initially created and set the data. Thus, I Cannot use UTC OR Local times because when de-serialized, they wouldn’t be the same as they were. I also cannot display the values in UTC, they must be displayed in Local Time. What I need is some odd serialization format that represents the concept of “Absolute Local Time”…that would be “Local Time without TimeZone”.

I can strip the TZ from the date string using Regex, that’s easy. but the sheer size of the object I’m dealing with means that more often than not I get an OutOfMemoryException. I watched it run without debug once and my used memory spiked from 100k to 800k during the operation. Not nice. And that was one of the smaller files.

Doc.DocumentElement.InnerXML = Regex.Replace(Doc.DocumentElement.InnerXML, "(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})(\\+|-)(\\d{2}:\\d{2})", "$1")

So far, the only option I have seen is to create duplicates of ALL the dateTime fields, set the DT fields themselves as “XmlIgnore()”, and then manually restore all the dates from the serialized string data after the doc is re-loaded. This is also not practical.
See Custom DateTime XML Serialization

Is there any way to force the serialization engine to serialize DateTime objects without their TimeZone data? Preferably something generic that doesn’t have to be individually applied to every DT property in the object?

!!EDIT!!

I may have found a partial solution. It might at least help moving forward. DateTimeKind.Unspecified, when serialized, doesn’t seem to have any TimeZone data attached to it. Is this the solution I’m looking for. Forcefully cast all my DateTime data using DateTime.SpecifyKind?

public DateTime? StartDate
    {
        get 
        { return _StartDate; }
        set
        {
            if (_StartDate == value)
                return;

            if (value != null)
                _StartDate = DateTime.SpecifyKind(value.Value, DateTimeKind.Unspecified);
            else
                _StartDate = value;

            OnPropertyChanged("StartDate");
        }
    }
  • 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-06-02T19:16:24+00:00Added an answer on June 2, 2026 at 7:16 pm

    Found an answer. This is not exactly what I was looking for, but serves as an effective work around.

    private static readonly Regex DTCheck = new Regex(@"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})([\+|-]\d{2}:\d{2})");
    
        /// <summary>
        /// Removes any instances of the TimeZoneOffset from the RigX after it has been serialized into an XMLString ++ Called from the "Save" process
        /// </summary>
        /// <param name="rigx"></param>
        /// <returns>StringReader referencing the re-formatted XML String</returns>
        private static StringReader RemoveTZOffsetFromRigX(RigX rigx)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XmlSerializer ser = new XmlSerializer(typeof(RigX));
    
            ser.Serialize(sw, rigx);
    
            string xmlText = sb.ToString();
    
            if (DTCheck.IsMatch(xmlText))
                xmlText = DTCheck.Replace(xmlText, "$1");
    
            StringReader Sreader = new StringReader(xmlText);
    
            return Sreader;
        }
    
        /// <summary>
        /// Removes the TimeZone offset from a RigX as referenced by stream.  Returns a reader linked to the new stream  ++ Called from the "Load" process
        /// </summary>
        /// <param name="stream">stream containing the initial RigX XML String</param>
        /// <returns>StringReader referencing the re-formatted XML String</returns>
        private StringReader RemoveTZOffsetFromXML(MemoryStream stream)
        {
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
    
            string xmlText = reader.ReadToEnd();
            reader.Close();
            stream.Close();
    
            if (DTCheck.IsMatch(xmlText))
                xmlText = DTCheck.Replace(xmlText, "$1");
    
            StringReader Sreader = new StringReader(xmlText);
    
            return Sreader;
        }
    

    After reading in the XML From the file, and before running it through the serializer, run the Regex on the bare XML Text to remove the offset. The function returns a string reader running against the modified XML string, which can then be run through a de-serialization into the object.

    Rather than using the serializer to save the xml directly to the output stream, you can use a stringBuilder to intercept the serialized xml. Then using the same process as during the loading procedure, you remove the TimeZone offset via RegularExpression, then return a StringReader linked to the modified text, which is then used to write the data back out into a file.

    Slightly hackish feeling, but effective. Very memory intensive though, avoid debugging the functions directly if you can, or if you have to, try not to evaluate the strings, last time I tried that it crashed my VS instance completely.

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

Sidebar

Related Questions

An odd issue that I have been trying to address in a project -
So this might be an odd question, but I have a C# program that
I have a very odd issue, where I've created a custom MSBuild task that
I have an odd problem...I'm using a documentation generator which generates a lot of
I have been writing a small java application (my first!), that does only a
Task: to build hash using map, where keys are the elements of the given
This is probably a truly basic thing that I'm simply having an odd time
I am new to SQL and been given a task. Following are the details:
So in my case this is very odd. I have 2 individual iTC accounts
Motivation: I'm solving problems that are caused by strange/mutated/odd/perverse cookies in ruby-on-rails. I have

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.