Index: branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs	(revision 1355)
@@ -63,11 +63,15 @@
     private readonly Stack<IAccessibleObject> compositeStack;
     private readonly PersistenceConfiguration persistenceConfiguration;
+    private readonly Dictionary<int, Type> typeIds;
 
     delegate void Thunk();
     private List<Thunk> finalFixes;
 
-    public DeSerializer() : this(PersistenceConfiguration.Instance) {}
+    public DeSerializer(IEnumerable<KeyValuePair<string, int>> typeCache) : 
+      this(typeCache, PersistenceConfiguration.Instance) {}
   
-    public DeSerializer(PersistenceConfiguration persistenceConfiguration) {
+    public DeSerializer(
+      IEnumerable<KeyValuePair<string, int>> typeCache,
+      PersistenceConfiguration persistenceConfiguration) {
       this.persistenceConfiguration = persistenceConfiguration;
       id2obj = new Dictionary<int, object>();
@@ -80,4 +84,9 @@
                      {typeof (Null), NullHandler}
                    };      
+      typeIds = new Dictionary<int, Type>();
+      foreach ( var pair in typeCache ) {
+        Type type = Type.GetType(pair.Key);
+        typeIds.Add(pair.Value, type);
+      }
     }
 
@@ -96,9 +105,10 @@
       CompositeStart start = (CompositeStart)token;
       object instance;
-      if (persistenceConfiguration.GetDecomposer(start.Type) != null) {
+      Type type = typeIds[int.Parse(start.TypeId)];
+      if (persistenceConfiguration.GetDecomposer(type) != null) {
         instance = new ParentReference();
         compositeStack.Push(new CustomObject(instance));        
       } else {        
-        instance = Activator.CreateInstance(start.Type, true);
+        instance = Activator.CreateInstance(type, true);
         Dictionary<string, DataMemberAccessor> accessorDict =
           StorableAttribute.GetAutostorableAccessors(instance);
@@ -109,10 +119,11 @@
     }
     private void CompositeEndHandler(IParseToken token) {
-      CompositeEnd end = (CompositeEnd)token;      
-      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(end.Type);
+      CompositeEnd end = (CompositeEnd)token;
+      Type type = typeIds[int.Parse(end.TypeId)];
+      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(type);
       if (decomposer != null) {
         CustomObject customObject = (CustomObject)compositeStack.Pop();
         object deserializedObject =
-          decomposer.DeSerialize(customObject.customValues, end.Type);
+          decomposer.DeSerialize(customObject.customValues, type);
         if ( end.Id != null )
           id2obj[(int)end.Id] = deserializedObject;        
@@ -126,6 +137,7 @@
     private void PrimitiveHandler(IParseToken token) {
       Primitive primitive = (Primitive)token;
+      Type type = typeIds[int.Parse(primitive.TypeId)];
       object value = persistenceConfiguration
-        .GetFormatter(XmlFormat.Instance, primitive.Type)
+        .GetFormatter(XmlFormat.Instance, type)
         .DeSerialize(primitive.SerializedValue);
       if ( ! value.GetType().IsValueType )
Index: branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs	(revision 1355)
@@ -2,4 +2,5 @@
 using System.Collections;
 using System;
+using System.Linq;
 
 namespace Persistence {
@@ -12,4 +13,13 @@
     private readonly Dictionary<Type, int> typeCache;
     private readonly PersistenceConfiguration persistenceConfiguration;
+
+    public Dictionary<string, int> TypeCache {
+      get {        
+        Dictionary<string, int> result = new Dictionary<string, int>();
+        foreach ( var pair in typeCache )
+          result.Add(pair.Key.AssemblyQualifiedName, pair.Value);
+        return result;                                     
+      }
+    }
 
     public Serializer(object obj) : this(obj, PersistenceConfiguration.Instance) {}
@@ -35,11 +45,5 @@
       IEnumerator<ISerializationToken> iterator = Serialize(rootAccessor);
       while (iterator.MoveNext())
-        yield return iterator.Current;
-      Console.WriteLine("TypeCache:");
-      foreach (var pair in typeCache) {                
-        Console.WriteLine("<TYPE id=\"{0}\" AssemblyQualifiedName=\"{1}\">",
-          pair.Value,
-          pair.Key.AssemblyQualifiedName);
-      }
+        yield return iterator.Current;      
     }
 
@@ -57,7 +61,8 @@
         yield break;
       }
-
+      
       if ( ! typeCache.ContainsKey(value.GetType()))
         typeCache.Add(value.GetType(), typeCache.Count);
+      int typeId = typeCache[value.GetType()];
 
       int? id = null;
@@ -70,5 +75,6 @@
       if (formatter != null) {
         yield return new PrimitiveToken(
-          accessor,
+          accessor.Name,
+          typeId,
           formatter.Serialize(value),          
           id);
@@ -76,5 +82,5 @@
       }
       
-      yield return new BeginToken(accessor, id);
+      yield return new BeginToken(accessor.Name, typeId, id);
       IDecomposer decomposer = persistenceConfiguration.GetDecomposer(value.GetType());      
 
@@ -85,5 +91,5 @@
             yield return iterator.Current;
         }
-        yield return new EndToken(accessor, id);
+        yield return new EndToken(accessor.Name, typeId, id);
         yield break;
       }
@@ -103,5 +109,5 @@
                                          value.GetType().FullName));
       }
-      yield return new EndToken(accessor, id);
+      yield return new EndToken(accessor.Name, typeId, id);
     }
     
Index: branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Persistence/Tokens.cs	(revision 1355)
@@ -6,27 +6,33 @@
   public interface ISerializationToken {
   }
-  public class BeginToken : ISerializationToken {
-    public readonly DataMemberAccessor Accessor;
+  public class BeginToken : ISerializationToken {    
+    public readonly string Name;
+    public readonly int? TypeId;
     public readonly int? Id;
-    public BeginToken(DataMemberAccessor accessor, int? id) {
-      Accessor = accessor;
+    public BeginToken(string name, int? typeId, int? id) {
+      Name = name;
+      TypeId = typeId;
       Id = id;
     }
   }
   public class EndToken : ISerializationToken {
-    public readonly DataMemberAccessor Accessor;
+    public readonly string Name;
+    public readonly int? TypeId;
     public readonly int? Id;
-    public EndToken(DataMemberAccessor accessor, int? id) {
-      Accessor = accessor;
+    public EndToken(string name, int? typeId, int? id) {
+      Name = name;
+      TypeId = typeId;
       Id = id;
     }
   }
   public class PrimitiveToken : ISerializationToken {
-    public readonly DataMemberAccessor Accessor;
-    public readonly object Data;
+    public readonly string Name;
+    public readonly int? TypeId;
     public readonly int? Id;
-    public PrimitiveToken(DataMemberAccessor accessor, object data, int? id) {
-      Accessor = accessor;
-      Data = data;
+    public readonly object SerialData;
+    public PrimitiveToken(string name, int? typeId, object serialData, int? id) {
+      Name = name;
+      TypeId = typeId;
+      SerialData = serialData;      
       Id = id;
     }
@@ -54,9 +60,9 @@
   public class CompositeStart : IParseToken {
     public readonly string Name;
-    public readonly Type Type;
+    public readonly string TypeId;
     public readonly int? Id;
-    public CompositeStart(string name, Type type, int? id) {
+    public CompositeStart(string name, string typeId, int? id) {
       Name = name;
-      Type = type;
+      TypeId = typeId;
       Id = id;
     }
@@ -64,9 +70,9 @@
   public class CompositeEnd : IParseToken {
     public readonly string Name;
-    public readonly Type Type;
+    public readonly string TypeId;
     public readonly int? Id;
-    public CompositeEnd(string name, Type type, int? id) {
+    public CompositeEnd(string name, string typeId, int? id) {
       Name = name;
-      Type = type;
+      TypeId = typeId;
       Id = id;
     }
@@ -74,10 +80,10 @@
   public class Primitive : IParseToken {
     public readonly string Name;
-    public readonly Type Type;
+    public readonly string TypeId;
     public readonly string SerializedValue;
     public readonly int? Id;
-    public Primitive(string name, Type type, string serilaizedValue, int? id) {
+    public Primitive(string name, string typeId, string serilaizedValue, int? id) {
       Name = name;
-      Type = type;
+      TypeId = typeId;
       SerializedValue = serilaizedValue;
       Id = id;
Index: branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs	(revision 1355)
@@ -52,7 +52,7 @@
     private string FormatBegin(ISerializationToken token) {      
       BeginToken beginToken = (BeginToken)token;
-      var attributes = new Dictionary<string, string> {
-        {"name", beginToken.Accessor.Name},
-        {"type", beginToken.Accessor.Get().GetType().AssemblyQualifiedName } };
+      var attributes = new Dictionary<string, string> {{"name", beginToken.Name}};
+      if ( beginToken.TypeId != null )
+        attributes.Add("typeId", beginToken.TypeId.ToString());
       if ( beginToken.Id != null ) 
         attributes.Add("id", beginToken.Id.ToString());                                           
@@ -72,12 +72,12 @@
       Dictionary<string, string> attributes =
         new Dictionary<string, string> {
-            {"type", dataToken.Accessor.Get().GetType().AssemblyQualifiedName}};
-      if ( !string.IsNullOrEmpty(dataToken.Accessor.Name) )
-        attributes.Add("name", dataToken.Accessor.Name);
+            {"typeId", dataToken.TypeId.ToString()}};
+      if ( !string.IsNullOrEmpty(dataToken.Name) )
+        attributes.Add("name", dataToken.Name);
       if ( dataToken.Id != null )
         attributes.Add("id", dataToken.Id.ToString());
       return Prefix +
         FormatNode("PRIMITIVE", attributes, NodeType.Start) +
-        dataToken.Data + "</PRIMITIVE>\n";      
+        dataToken.SerialData + "</PRIMITIVE>\n";      
     }
 
@@ -98,4 +98,13 @@
       return Prefix + FormatNode("NULL", attributes, NodeType.Inline) + "\n";
     }
+
+    public IEnumerable<string> Format(Dictionary<string, int> typeCache) {
+      yield return "<TYPECACHE>";
+      foreach ( var pair in typeCache ) {
+        yield return String.Format("  <TYPE id=\"{0}\" name=\"{1}\"/>",
+                                   pair.Value, pair.Key);        
+      }
+      yield return "</TYPECACHE>";
+    }
   }
 }
Index: branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs	(revision 1355)
@@ -6,4 +6,6 @@
 
 namespace Persistence {
+
+
   public class XmlParser : IEnumerable<IParseToken> {
 
@@ -52,5 +54,5 @@
       yield return new Primitive(
         reader.GetAttribute("name"),
-        Type.GetType(reader.GetAttribute("type")),
+        reader.GetAttribute("typeId"),        
         reader.ReadString(),
         id);
@@ -58,14 +60,14 @@
     private IEnumerator<IParseToken> ParseComposite() {
       string name = reader.GetAttribute("name");      
-      Type type = Type.GetType(reader.GetAttribute("type"));
+      string typeId = reader.GetAttribute("typeId");
       string idString = reader.GetAttribute("id");
       int? id = null;
       if (idString != null)
         id = int.Parse(idString);      
-      yield return new CompositeStart(name, type, id);
+      yield return new CompositeStart(name, typeId, id);
       IEnumerator<IParseToken> iterator = GetEnumerator();
       while (iterator.MoveNext())
         yield return iterator.Current;
-      yield return new CompositeEnd(name, type, id);
+      yield return new CompositeEnd(name, typeId, id);
     }
     private IEnumerator<IParseToken> ParseReference() {
@@ -80,4 +82,15 @@
       return GetEnumerator();
     }
+    public static Dictionary<string, int> ParseTypeCache(TextReader reader) {
+      Dictionary<string, int> typeCache = new Dictionary<string, int>();
+      XmlReader xmlReader = XmlReader.Create(reader);
+      while ( xmlReader.Read() ) {
+        if (xmlReader.Name == "TYPE") {          
+          typeCache.Add(xmlReader.GetAttribute("name")
+          , int.Parse(xmlReader.GetAttribute("id")));
+        }
+      }
+      return typeCache;
+    }
   }  
 }
Index: branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs
===================================================================
--- branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs	(revision 1354)
+++ branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs	(revision 1355)
@@ -23,6 +23,13 @@
       }
       writer.Close();
+      writer = new StreamWriter("test-types.xml");
+      foreach (string line in xmlFormatter.Format(s.TypeCache)) {
+        writer.WriteLine(line);
+        Console.Out.WriteLine(line);
+      }
+      writer.Close();
+      
       XmlParser parser = new XmlParser(new StreamReader("test.xml"));
-      DeSerializer deSerializer = new DeSerializer();        
+      DeSerializer deSerializer = new DeSerializer(XmlParser.ParseTypeCache(new StreamReader("test-types.xml")));        
       object o = deSerializer.DeSerialize(parser);
       Root t = CloningFactory.DefaultClone(r);
@@ -42,5 +49,5 @@
       writer.Close();
       XmlParser parser = new XmlParser(new StreamReader("test2.xml"));
-      DeSerializer deSerializer = new DeSerializer();
+      DeSerializer deSerializer = new DeSerializer(XmlParser.ParseTypeCache(new StreamReader("test-types.xml")));              
       object o = deSerializer.DeSerialize(parser);
       Manager n = CloningFactory.DefaultClone(m);
@@ -120,5 +127,5 @@
 
     public static void Main() {      
-      //Test1();      
+      Test1();      
       //Test2();
       //SpeedTest();
