By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

XML Serialization in dynamically loaded assembly

P: n/a
I am serializing/deserializing a class (Class1) using the XmlSerializer
object in the System.Xml.Serialization namespace in .Net 2.0. Class1 has
some strings and ints and two lists of other simple serializable classes
(Class2 and Class3)

Class1, Class2 and Class3 are defined in an assembly (Assembly1) which is
loaded by another assembly (Assembly2). When I statically reference
Assembly1 in Assembly2, serialization and deserialization work correctly.
When I dynamically load Assembly1 into Assembly2 using 'Assembly.Load',
serialization and deserialization do not work. I get the following error for

System.InvalidOperationException: There was an error generating the XML
document. ---System.TypeInitializationException: The type initializer for
'Microsoft.Xml.Serialization.GeneratedAssembly.Xml SerializationWriterClass1'
threw an exception. ---System.NullReferenceException: Object reference not
set to an instance of an object.
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterClass1..cctor()
--- End of inner exception stack trace ---
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterClass1..ctor()
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializerContract.get_Writer()
at System.Xml.Serialization.TempAssembly.InvokeWriter (XmlMapping mapping,
XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)

I am not sure what is happening but I tried pre-generating the serialization
assembly using Sgen and adding a reference to this assembly in Assembly1 but
I still get the same error.

Can anyone advise me what I'm doing wrong here? Thanks!
Sep 30 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.