Although the code may seem to be compiled in memory (CompilerParameters.GenerateInMemory), this is not what is actually happening. The same compiler as in Visual Studio is used to compile the code (csc.exe). It starts with CreateProcess (like Process.Start) and runs outside the process to compile assembly code on disk in a temporary folder. The GenerateInMemory parameter calls Assembly.LoadFrom () to load the assembly.
You will get the equivalent of syntax checking by simply setting GenerateInMemory to false and removing OutputAssembly after it is completed.
Although this may seem to be the opposite, the huge benefit is that it will not affect your process. This will delay you until C # 5.0 leaves.
Hans passant
source share