views:

23

answers:

1

Hi,

I am using reflection to emit some dynamic types at runtime. Why is not really important.

My problem right now is that using classes like AssemblyBuilder, ModuleBuilder and TypeBuilder, a type is generated perfectly and I can work with it without a problem.

However there can be instances where I might need to change the definition of the generated type. How do I remove a generated type from a generated assembly?

+3  A: 

You'd need to generate the types in their own AppDomain and unload the whole thing. Even then, you'd have to be careful not to let an instance cross the domain boundary, else it might load the type into your primary domain.

Steven Sudit
One hint: While referencing these types in your own AppDomain sucks them in and ruins your ability to regenerate them, the opposite is not true. In other words, it's perfectly fine to create classes that you intend to run in the new AppDomain. The only trick is that you'll need to instantiate such a class in that AppDomain and then call it through .NET remoting. It's kind of a mess, but not *that* hard.
Steven Sudit