6

I am trying to find all the references of a type symbol using FindReferencesAsync. It works well for references within a C# project; however, cross-project references don't appear. Here is the code that I am using.

var model = compilation.GetSemanticModel(_sourceFile.GetSyntaxTree());
ISymbol classSymbol = model.GetDeclaredSymbol(typeDeclarationSyntax);
referencedSymbols.AddRange(SymbolFinder
                    .FindReferencesAsync(classSymbol, _solution)
                    .Result.ToList());
Tushar
  • 790
  • 7
  • 12
  • Just do be clear, do you compilation have a reference to the project that is contain a using type? – George Alexandria Feb 13 '19 at 15:40
  • The loaded project shows a project reference in ProjectReferences attribute. However, compilation diagnostics show errors (type or namespace 'Lib' could not be found (are you missing a using directive or an assembly reference?) – Tushar Feb 13 '19 at 16:16
  • How are you opening the project and creating the compilation? You may need to manually add `ProjectReferences` yourself. This is probably the case if you're seeing compilation errors. – JoshVarty Feb 19 '19 at 17:26

1 Answers1

0

I spent a considerable time on this problem. I tried, among others, to add meta-references and project references but nothing worked. Finally, I was able to resolve it by looking at the Diagnostic information provided while creating an instance of a project. Once all the critical issues reported in diagnostics are resolved, I could see all the references of a symbol even across the projects.

Tushar
  • 790
  • 7
  • 12