Can I compile and execute a C # expression without saving the assembly to disk?

I can compile, get an instance, and call a method of any type in C # programmaticaly. There is a lot of information about this, including StackOverflow ( How can I evaluate a C # expression dynamically? ). My problem is that I am in a web environment and cannot save anything in the / bin directory. I can compile "in-memory" as the above link suggests, but then I cannot "unload" my custom assembly from the current AppDomain. After a while, this will become a huge memory problem. Is it possible to open a new AppDomain, compile a new in-memory assembly, evaluate some expression or access some member of this assembly inside this new AppDomain and safely kill AppDomain when it is done, all that without saving anything to the hard drive? Thanks in advance for any links, suggestions, etc.

+6
c # compilation
source share
2 answers

Have you looked at DynamicMethod in .Net? This type creates garbage collection activated in memory methods using Reflection.Emit. This is similar to what you are looking for.

+2
source share
+1
source share

All Articles