0

I use following to compile C# in runtime:

CompilerParameters parameters = new CompilerParameters
        {
            GenerateInMemory = true,
            GenerateExecutable = true,
            IncludeDebugInformation =  true
        };


        // True - memory generation, false - external file generation
        // True - exe file generation, false - dll file generation

        var res = pro.CompileAssemblyFromSource(parameters,
            code);

        Assembly assembly = res.CompiledAssembly;
        Type program = assembly.GetType("First.Program");
        MethodInfo main = program.GetMethod("Main");
        var invoke = main?.Invoke(null, null);

res.Output is an empty list, and If the code has Console.WriteLine(), It gets written to main application's console, however; I wanna grab what is written.

Talha Talip Açıkgöz
  • 1,821
  • 4
  • 15
  • 28

1 Answers1

0

You also should check res.Errors. If there are errors, then they will be there instead. If both Errors and Output are empty, then you may have had a successful compilation without any output. Check: cr.NativeCompilerReturnValue.ToString()

AaronLS
  • 37,329
  • 20
  • 143
  • 202