Destroying emitted enumerations.

  • Thread starter Thread starter someone else
  • Start date Start date
S

someone else

I have some code that creates dynamic enumerations for use in a PropertyGrid
control. This all works perfectly but the memory usage of the program
increases quite quicly when viewing the PropertyGrids displaying these
enumerations (one of which has a few hundred items in). I believe this is
because the dynamically generated enumerations are not being destroyed.

I have not been able to find a mechanism for deleting/destroying dynamically
generated enumerations so I decided to try to create them in a separate
AppDomain which could be unloaded when the enumerations were no longer
needed.

So I changed my code from: -

-> AppDomain ad = AppDomain.CurrentDomain;

to: -

-> AppDomain ad = AppDomain.CreateDomain( "EmittedTypes",
AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.SetupInformation );

I thought this would create a new AppDomain into which I could place the
enumerations. It all works except for when I make the call: -

-> AssemblyBuilder ab = ad.DefineDynamicAssembly( an,
AssemblyBuilderAccess.RunAndSave );

With the error, "An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll - Additional information: The type
System.Reflection.Emit.AssemblyBuilder in Assembly mscorlib,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not
marked as serializable.".

Any information that might point me in the right direction would be very
helpful.

Thank you in advance,

Jonathan Williamson
 
Have you tried adding the Serialize attribute to the class in question?
Given the assembly, and the emitted class, all you have to do is add the
attribute when you call ModuleBuilder.DefineType.

This help?

Chris
 
Back
Top