System.Diagnostics not found when adding reference to compilation

Topics: APIs
Jul 17, 2014 at 7:26 PM
I'm trying to compile the code that has a reference to System.Diagnostics like this:
var compilation = CSharpCompilation.Create("CSCodeGenTets").WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
                var assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
                var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
                var references = new[]
                {
                    new MetadataFileReference(Path.Combine(assemblyPath, "mscorlib.dll")),
                    new MetadataFileReference(Path.Combine(assemblyPath, "System.dll")),
                    new MetadataFileReference(Path.Combine(assemblyPath, "System.Core.dll")),
                    new MetadataFileReference(Path.Combine(assemblyPath, "System.Collections.dll")),
                    new MetadataFileReference(entryAssembly.Location)
                };

                compilation = compilation.AddReferences(references);
                var diagnostics = compilation.GetDiagnostics();
And it gives me errors like: error CS0246: The type or namespace name 'System.Diagnostics' could not be found (are you missing a using directive or an assembly reference?)
What am I missing here?