I am trying to write a code that will test if any method has ExecuteReader without corresponding Close reader - basic test to play with, just checks if ExecuteReader and Close are in the same block.
This basic test was easy to implement and perform with Roslyn on hard-coded string with class code. However, when I try to open a solution programmaticaly and compile a project or document I get a lot of errors, here is the excerpt:
error CS0246: The type or namespace name 'Roslyn' could not be found (are you missing a using directive or an assembly reference?)
error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'InvocationExpressionSyntax' could not be found (are you missing a using directive or an assembly reference?)
Here is the code:
IWorkspace workspace = Workspace.LoadSolution(@"d:\test\test.sln"); ISolution solution = workspace.CurrentSolution; foreach (IProject project in solution.Projects) { var compilation = project.GetCompilation(); // tried with .AddReferences(project.MetadataReferences); also foreach (var diagnostic in compilation.GetDiagnostics()) { diagnostic.ToString(); Console.WriteLine(diagnostic.Info); }
I don't know if it matters, my test application is Roslyn Console Application.