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?