For example, if you use the following constructor to create several XmlSerializer objects, a new dynamic assembly is created every time:
public void XmlSerializer( Type t, Type extraTypes)
- Create one instance of the XmlSerializer class, and put that instance in the cache by using the caching APIs. For example, for a .dll file that is named HighSchool, the following code caches one instance of the XmlSerializer class:Use the instance of the XmlSerializer class that you put in the cache instead of creating a new XmlSerializer object every time.
XmlSerializer mySerializer = new XmlSerializer(typeof(HighSchool.MyClass), attrOverrides, extraTypes, root, "http://www.microsoft.com");
Cache["HighSchoolSerializer"] = mySerializer
- Use the following XmlSerializer class constructors. These class constructors cache the assemblies:
In the .NET Framework version 1.0
In the .NET Framework version 1.1
public XmlSerializer(Type type);
public XmlSerializer(Type type, string defaultNamespace);
- Declare the XmlSerializer object to be a static member of a class.