Domanda

I used CSharpCodeProvider to compile and generate a new namespace in the memory for temporary use only. But this namespace should be deleted from the memory after certain period of time in order to allow for the next generated code to override the same identifiers of all generated classes and methods.

È stato utile?

Soluzione

There is only one way a loaded type can be unloaded: if it is a part of a collectible assembly.

But collectible assemblies can be only created through Reflection.Emit, not CSharpCodeProvider. Because of that, I'm not sure if using a collectible assembly is an option for you. If not, you will need some other option (like unloading AppDomains).

Altri suggerimenti

No way. Class unload only happens - attention - when unloading a AppDomain.

Your best bet is to do all the code generation in a child-appdomain (will be same process), but that will not be trivial (the child appdomain needs proxies of all reachable object via remoting).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top