title: Roslyn / Find References - Can't properly load Workspace
body: <p>I'm trying to write some code to find all method invocations of any given method as I am looking to create an open source UML Sequence Diagramming tool. I'm having trouble, however, getting past the first few lines of code :/</p>
  
  <p>The API appears to have changed drastically and I can't seem to infer proper usage by looking at the code.</p>
  
  <p>When I do:</p>
  
  <pre><code>    var workspace = new CustomWorkspace();
      string solutionPath = @"C:\Workspace\RoslynTest\RoslynTest.sln";
      var solution = workspace.CurrentSolution;
  </code></pre>
  
  <p>I find that workspace.CurrentSolution has 0 Projects. I figured this would be the equivalent to what was previously <code>Workspace.LoadSolution( string solutionFile )</code> which would then supposedly contain any Projects in the Solution, but I am not finding any success with this path.</p>
  
  <p>I am terribly confused 0.o</p>
  
  <p>If someone could offer some additional guidance as to how I can use the FindReferences API to identify all invocations of a particular method, it would be very much appreciated!</p>
  
  <p>Alternatively, would I be better off taking a static-analysis approach? I would like to support things like lambdas, iterator methods and async.</p>
  
  <p>====================================================================</p>
  
  <p>Edit -</p>
  
  <p>Here is a full example based on the accepted answer:</p>
  
  <pre><code>using System.Linq;
  using Microsoft.CodeAnalysis.CSharp;
  using Microsoft.CodeAnalysis.CSharp.Syntax;
  using Microsoft.CodeAnalysis.MSBuild;
  using Microsoft.CodeAnalysis.FindSymbols;
  using System.Diagnostics;
  
  namespace RoslynTest
  {
      class Program
      {
          static void Main(string[] args)
          {
              string solutionPath = @"C:\Workspace\RoslynTest\RoslynTest.sln";
              var workspace = MSBuildWorkspace.Create();
              var solution = workspace.OpenSolutionAsync(solutionPath).Result;
              var project = solution.Projects.Where(p =&gt; p.Name == "RoslynTest").First();
              var compilation = project.GetCompilationAsync().Result;
              var programClass = compilation.GetTypeByMetadataName("RoslynTest.Program");
  
              var barMethod = programClass.GetMembers("Bar").First();
              var fooMethod = programClass.GetMembers("Foo").First();
  
              var barResult = SymbolFinder.FindReferencesAsync(barMethod, solution).Result.ToList();
              var fooResult = SymbolFinder.FindReferencesAsync(fooMethod, solution).Result.ToList();
  
              Debug.Assert(barResult.First().Locations.Count() == 1);
              Debug.Assert(fooResult.First().Locations.Count() == 0);
          }
  
          public bool Foo()
          {
              return "Bar" == Bar();
          }
  
          public string Bar()
          {
              return "Bar";
          }
      }
  }
  </code></pre>