TypeAccessException while xml serializing a type in dynamic (merged) assembly
===

I use ILMerge to merge two assemblies which have some user defined classes, say A and B. In the merged assembly, both these classes are public. I give this merged assembly to another module and that creates an object of type A, puts in some data and serializes to Xml. While I am able to instantiate an object of type A, I am not able to serialize it (Type A has the Serializable attribute defined). I get the following exception. 


    System.InvalidOperationException was caught
      Message=There was an error generating the XML document.
      Source=System.Xml
      StackTrace:
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
       at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o)

      InnerException: System.TypeAccessException
       Message=Attempt by method 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterA.Write3_A(System.Object)' to access type 'SomeNamespace.A' failed.
       Source=vhrgczis
       TypeName=""
       StackTrace:
            at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterA.Write3_A(Object o)
       


If I try to create an object of Type A from the original unmerged assemblies and serialize, the process succeeds. 

What could be the problem here?

Thanks so much in advance.