Reputation:
Consider I have a program running, which should do the following- Should read some code from a text file and should execute it in its own Assembly space so that the new code being executed can access all components of the code already running. How is that possible?? Help please.
Upvotes: 4
Views: 315
Reputation: 4466
By assembly space, do you mean AppDomain?
You might want to look at IronPython. As a scripting language it is better suited for being dynamically added to the program at runtime.
Otherwise:
You have access to the C# (and VB.NET) compiler via the Microsoft.CSharp.CSharpCodeProvider sitting in System.dll.
You can use it to compile that text file into a separate dll (possibly in-memory). Make sure that you add your currently executing assembly as a reference while compiling. Then you can either
Either way, you'll have to use reflection to call your dynamically loaded code.
Upvotes: 2
Reputation: 14875
Not sure how the magic works, but I'd look at MyGeneration, which is open source and acheives what you want to do. It can read a file of C#, VB.Net, and JScript and then build/compile those scripts and gives them access to it's own set of classes and assemblies.
Upvotes: 0