3

The problem (and some unnecessary information): I am creating a chat bot in C# (not chatterbot), and want users to be able to run custom code on the bot. Basically, you send a string message over the network, and the bot runs the code contained in it.

I have looked into and actually implemented/used CSharpCodeProvider, however, this has the problem of every time custom code is compiled, it adds another Assembly to the AppDomain (which is impossible to remove). When you take into account that tens or hundreds of separate custom code invokes may occur in a single lifetime, this becomes a problem.

My idea is that there might be a interpreted language or some such thing that is able to be invoked from C#.

usr
  • 168,620
  • 35
  • 240
  • 369

1 Answers1

2

You can remove an assembly if you remove the entire appdomain. So you could create a fresh appdomain, load the assembly there (or compile it from there) and dispose of it after use.

You could recycle the appdomain every 100 statements or so in order to amortize the (small) time it takes to cycle one.

usr
  • 168,620
  • 35
  • 240
  • 369
  • Could you link me a tutorial to create an appdomain and compile code into it? I don't know what to google for, all my previous searches have turned up nothing. –  Jul 26 '12 at 23:45
  • Googling for ".net create appdomain assembly compile" turns up http://stackoverflow.com/questions/3512931/how-can-i-use-codedom-to-create-and-load-an-assembly-in-an-appdomain among others which might be helpful. – usr Jul 27 '12 at 10:18