469,927 Members | 1,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

XML Serialization in dynamically loaded assembly

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
serialization:

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.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterClass1..cctor()
--- End of inner exception stack trace ---
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterClass1..ctor()
at
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
0 2237

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Hoehne | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.