views:

68

answers:

2

I can compile, get an instance and invoke a method of any C# type programmaticaly. There lots of info on that, including the StackOverflow (http://stackoverflow.com/questions/53844/how-can-i-evaluate-a-c-expression-dynamically). My problem is that I'm in the web environment and cannot save anything to /bin directory. I can compile "in-memory" as the above mentioned link suggests but then I won't be able to "unload" my custom assembly from the current AppDomain. After a while that will become a huge memory problem. Is it possible to open a new AppDomain, compile new assembly "in-memory", evaluate some expression or access some member of that assembly inside of that new AppDomain and kill that AppDomain safely when done, all that without saving anything to a hard drive? Thanks in advance for any links, suggestions, etc.

+1  A: 

Rick Strahl has a pretty good post on the subject here.

driis
The author says what I stated in my question as well: You either stuck with a huge memory problem or you execute a new code in its own AppDomain. But the article itself was fun, thanks for sharing!
Sasha
+2  A: 

Have you taken a look at the DynamicMethod type in .Net? This type creates garbage collection enabled in memory methods using Reflection.Emit. This sounds like exactly what you're looking for.

JaredPar
I entirely missed the whole DynamicMethod thing. Reading already... Still can't see how to use it to evaluate a simple thing like b = Evaluate("5 < 6"). Looking more, hoping I just miss something. Thank you!
Sasha