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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:03:23+00:00 2026-06-13T13:03:23+00:00

I tried Mono – it creates serializers in 1 millisecond vs 60 by .NET

  • 0

I tried Mono – it creates serializers in 1 millisecond vs 60 by .NET 4.0. May be somebody ported Mono serializers generator as reusable lib? Or can give me exact list of Mono assemblies to use if I will try to port?


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace serialization
{
    [Serializable]
    public sealed class UserCredentials1
    {
        public string Username { get; set; }
        public string Password { get; set; }

        public override string ToString()
        {
            return string.Format("Username: {0}, Password: {1}", Username, Password);
        }
    }

    [Serializable]
    public sealed class UserCredentials2
    {
        public string Username { get; set; }
        public string Password { get; set; }

        public override string ToString()
        {
            return string.Format("Username: {0}, Password: {1}", Username, Password);
        }
    }

    //.NET 4.0
    //native=60.757
    //compiled=2.2602
    //Username: CTTTOM, Password: WoEIPX6Qqf11j9vKn01bAA==

    //MONO:
    //mono serialization.exe
    //native=0.1589
    //compiled=0.1337
    //Username: CTTTOM, Password: WoEIPX6Qqf11j9vKn01bAA==

    class Program
    {
        static void Main(string[] args)
        {
            string xml1 = @"      " +
             @" CTTTOM" +
        @" WoEIPX6Qqf11j9vKn01bAA==" +
                 @"";

            string xml2 = @"" +
@" CTTTOM" +
@" WoEIPX6Qqf11j9vKn01bAA==" +
     @"";

            //warm up
            Type targetType1 = typeof(UserCredentials1);
            XmlSerializer nativeSerializer1 = new XmlSerializer(targetType1);
            Type targetType2 = typeof(UserCredentials2);
            nativeSerializer1.Deserialize(new XmlTextReader(new StringReader(xml1)));

            var native = new Stopwatch();
            native.Start();
            XmlSerializer nativeSerializer2 = new XmlSerializer(targetType2);
            native.Stop();
            Console.WriteLine("native=" + native.Elapsed.TotalMilliseconds);

            var compiled = new Stopwatch();
            compiled.Start();
            var de = nativeSerializer2.Deserialize(new XmlTextReader(new StringReader(xml2)));
            compiled.Stop();
            Console.WriteLine("compiled=" + compiled.Elapsed.TotalMilliseconds);
            Console.Write(de.ToString());
            Console.ReadKey();
        }
    }
}

EDIT

I made first step to migration, see https://github.com/asd-and-Rizzo/mono .
Done test with generic list of objects using “mono serialization.exe”, mouse click run with .NET serialization and ported Mono serialization. Ported version gives ~10 times faster default serializers generation then .NET one.

EDIT

Found in MSDN regarding XML serialization configuration .NET 4.5 (http://msdn.microsoft.com/en-us/library/ms229754.aspx):

useLegacySerializationGeneration
Specifies whether the XmlSerializer uses legacy serialization generation which generates assemblies by writing C# code to a file and then compiling it to an assembly. The default is false.

  • 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-13T13:03:24+00:00Added an answer on June 13, 2026 at 1:03 pm

    Made port which can be build and used against .NET 3.5.

    
    extern alias mono;
    using XmlSerializer = mono::System.Xml.Serialization.XmlSerializer;
    
    

    https://github.com/asd-and-Rizzo/mono/blob/master/mcs/class/System.XML/Mono.Xml.Serialization.sln

    Mono does not compiles serializers.

    Could be interesting to try managed Mono.CSharp.dll to compile serializers.

    EDIT

    I added several tests could go to Mono trunk. All my changes related only to port are under EXTEND_EMBRACE_XMLSER compilation symbol.

    Our product tests noted that Mono serializes and deserializes what .NET does not. It is even better for our case, bat can be problem for others if error expected. All tests are commited to System.Xml tests.

    public class HardlySerializableObject
    {
        private HardlySerializableObject() { }
    
        public HardlySerializableObject(object value) { }
    
        public string Property1 { get { return "^_^"; } }
    
        public int Property2 { get; private set; }
    
        public static HardlySerializableObject Create()
        {
            return new HardlySerializableObject("any");
        }
    
        protected bool Equals(HardlySerializableObject other)
        {
            return Property2 == other.Property2 && Property1 == other.Property1;
        }
    
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != this.GetType()) return false;
            return Equals((HardlySerializableObject)obj);
        }
    
        public override int GetHashCode()
        {
            return Property2;
        }
    }
    

    EDIT2

    When to serialize one object of type A and try do deserialize other object of type B from that string then:

    • .NET throws InvalidOperationException.
    • Mono throws XmlException.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Mono claims to be compatible with .NET. Have you tried it? Can you share
I am trying Mono/.Net 3.5 under Linux (Ubuntu). I tried to use threads in
Tried a bunch of things but I can't get it to work consistently amid
Heys all, I've tried to use NRefactory(Vb) https://github.com/icsharpcode/NRefactory/ but it didn't come with mono.cecil.dll
What is the GTK equivalent to BackgroundWorker in Mono? I've tried the following website:
I compiled my application with monodevelop. And tried to run with mono on Linux.
We are using the Mono (2.10) XSP4 webserver to host an ASP.Net MVC3 web-application
I'm looking for an IMAP4 library for .NET (preferably working on Mono out of
I recently installed mono for Android and today I tried to get started. In
Currently I am experimenting with Mono, and creating a small testproject. When I tried

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.