Connecting Tech Pros Worldwide Help | Site Map

XML Serialization in dynamically loaded assembly

  #1  
Old September 30th, 2008, 11:45 AM
=?Utf-8?B?Y211cmFsaQ==?=
Guest
 
Posts: 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
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!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a Webservice in Reflected class dev@matthewpayne.co.uk answers 0 October 12th, 2007 10:35 AM
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
Serialization issues using .NET Framework 2.0? Michael Hoehne answers 3 July 1st, 2006 09:40 AM
GetAssemblies() & WebService... Norm Dotti answers 4 July 21st, 2005 10:42 AM