4

I'm using Microsoft's CSharpCodeProvider to dynamically create and execute code.

Right now, it creates an assembly in a dll, located inside a temporary folder.

I want for it to create an assembly in memory without having to write it to a hard drive.

How do I do that?

Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224
  • Duplicate - http://stackoverflow.com/q/826398/763026 – Angshuman Agarwal Jun 16 '12 at 21:44
  • 1
    Not a duplicate. The thread provided concerned itself with how to use CSharpCodeProvider. I'm asking how to use it without generating temporary assemblies – Arsen Zahray Jun 16 '12 at 21:46
  • I like to know...What is the use of this compile and save the DLL onto memory only? – The Original Android Jun 17 '12 at 00:47
  • I ran into this when attempting genetic programming in .net. You need to automatically generate and compile code, run it and test it as quick as possible. A disk hit here is undesirable. Back in .net2.0 days, it seemed this was unavoidable. I don't know if this has changed. – spender Jun 17 '12 at 01:27

1 Answers1

11

I think you're just looking for CompilerParameters.GenerateInMemory.

Set that to true for the compiler parameters you pass in when compiling, and it won't generate a file.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Although this does a temporary disk write because the code-dom is invoking csc.exe – usr Jun 16 '12 at 21:47
  • @usr: That's an implementation detail I'd say. I suspect in the future it may well not do so. I'm not even 100% sure of the truth of that claim in all situations today. – Jon Skeet Jun 16 '12 at 21:48
  • There is no in-memory compiler technology on the .NET platform available today (AFAIK). Last time I checked was in the .NET 2.0 days. – usr Jun 16 '12 at 21:50
  • 1
    @usr: Well bear in mind that dynamic typing already requires a lot of the compiler to be present in memory, and the work the compiler team's been doing recently may well change this whole situation very significantly in the future. (I expect there to *only* be the managed compiler eventually.) – Jon Skeet Jun 16 '12 at 21:53