0

I am working with .net and codedom in an environment where I would like to avoid (or preferably, eliminate) file system access.

My current code:

Private Sub ProcessCommand(ByVal command As String)
    Dim MyProvider As New VBCodeProvider 
    Dim cp As New CompilerParameters     
    cp.GenerateExecutable = True        
    cp.GenerateInMemory = True           
    Dim TempModuleSource As String = command

    cp.ReferencedAssemblies.Add("System.dll") 
    cp.ReferencedAssemblies.Add("System.Windows.Forms.dll") 
    cp.IncludeDebugInformation = False

    Dim cr As CompilerResults = MyProvider.CompileAssemblyFromSource(cp, TempModuleSource)
    If cr.Errors.Count > 0 Then

        Throw New ArgumentOutOfRangeException("Invalid Expression - please use something VB could evaluate")
    Else

        cr.CompiledAssembly.EntryPoint.Invoke(Nothing, Nothing)
    End If
End Sub

I was surprised to see that GenerateInMemory = True didn't really make it generate in memory. Instead, the binary was compiled and stored in a temp file. Is there are way to force codedom to store the output in memory? Maybe by forcing the binary not to use temp files perhaps?

svick
  • 236,525
  • 50
  • 385
  • 514
Sihan Zheng
  • 465
  • 4
  • 17

1 Answers1

1

This is not an option, the current VB.NET and C# compilers (vbc.exe and csc.exe) can only generate assemblies to disk. This may change some day when the Roslyn project ships but that's future music.

This doesn't otherwise affect the efficiency of compilation or assembly loading at all, your program will load the assembly from memory. The file system cache takes care of this.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks, Performance is what I'm worried about in this scenario. So as long as it is in the file system cache, I'm not worried – Sihan Zheng Aug 08 '12 at 18:19