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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:25:49+00:00 2026-05-31T15:25:49+00:00

I’ve recently been exposed to some code which consistently uses Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract.getSerializer(typeof(X)) to create a

  • 0

I’ve recently been exposed to some code which consistently uses Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract.getSerializer(typeof(X)) to create a new serializer, where X is the type of object being deserialized. When looking up documentation, most documentation would use new XmlSerializer(typeof(X)), and I could hardly find any documentation on XmlSerializerContract (and the only official documentation I did find pertained to Outlook).

What are the benefits to using Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract.getSerializer() versus new XmlSerializer()? Under what scenarios would I want to use each?

  • 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-31T15:25:50+00:00Added an answer on May 31, 2026 at 3:25 pm

    For performance optimization, XmlSerializer (and XmlSerializerFactory) generate temporary assembly containing serializer for particular types. The type that you have mentioned (Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializerContract) are from these generated assemblies (see http://treyhutcheson.wordpress.com/2007/02/20/dynamic-interface-implementations/) – so it’s quite natural that you haven’t found any documentation for the same.

    Frankly, to me it seems to be some hack solution probably to work-around memory leak issues related XmlSerializer – unless specific constructors are used, XmlSerializer would keep on generating more dynamic assemblies and thereby increasing memory foot-print. Quote from MSDN on the same:

    Dynamically Generated Assemblies

    To increase performance, the XML serialization infrastructure
    dynamically generates assemblies to serialize and deserialize
    specified types. The infrastructure finds and reuses those assemblies.
    This behavior occurs only when using the following constructors:

    XmlSerializer.XmlSerializer(Type)

    XmlSerializer.XmlSerializer(Type, String)

    If you use any of the other constructors, multiple versions of the
    same assembly are generated and never unloaded, which results in a
    memory leak and poor performance. The easiest solution is to use one
    of the previously mentioned two constructors. Otherwise, you must
    cache the assemblies in a Hashtable, as shown in the following
    example.

    My advise would be to of course find out the actual reason for using undocumented code from generated assembly from concerned developers but regardless prepare to migrate away from the same by using XmlSerializer/XmlSerializerFactory – you can always use your own caching solution if needed (in case you are not using those two particular constructors). Don’t forget to test your code rigorously.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words

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.