System.Xml.Serialization - deserializing xml to types created in dynamic assembly

  • Thread starter Thread starter rein.petersen
  • Start date Start date
R

rein.petersen

Hi All,

I've been working on a saved dynamic assembly that holds all the types
and corresponding xml serialization attributes I need to deserialize
xml documents into objects.

You might wonder why I would choose a dynamic assembly over simply
coding the types at compile time - the simple answer is I don't know
what the types will be before hand and I only have an xml schema (from
which I build the dynamic assembly) with various attributes that change
frequently.

Since the schema only defines data types (methods,events,delegates
could probably be defined within xs:appinfo tags but in my case they
are not), I needed a way to add functionality to these dynamically
created classes which were otherwise, nothing more than just data
stubs.

The method I chose was to define (at compile-time) abstract base
classes from which classes in my dynamic assembly could inherit. Now
these simple data-stub classes had a complement of methods to enable
them to do more than simply hold data in fields.

Unfortunately, it seems that since my dynamic classes now inherit from
classes defined at compile-time, the xml serializer gets confused (see
error and stack trace below).

It worked fine before I added the inheritance - maybe I need a
reference (somehow) to the hardcoded assembly containing the types I
inherit from in my dynamic assembly.

Any suggestions? Thanks in advance, Rein

[[error and stack trace]]

"An unhandled exception of type 'SystemIO.FileNotFoundException'
occurred in mscorlib.dll.

Addtional Information: File or assembly name [xxxxx.dll], or one of
it's dependencies, was not found."

stack trace:

at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean
throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)

at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark&
stackMark)

at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence
assemblySecurity)

at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()

at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()

at System.Xml.Serialization.Compiler.Compile()

at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[]
xmlMappings)

at
System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlTypeMapping
xmlTypeMapping)

at System.Xml.Serialization.XmlSerializer..ctor(Type type, String
defaultNamespace)

at System.Xml.Serialization.XmlSerializer..ctor(Type type)
 
Back
Top