I'm trying to find the references to a method in the entire solution. Below is the code snippet. The same snippet works fine for all the solutions except one. I've subscribed to the workspaceFailed event and there are no workspace or solution load errors. I've even removed duplicate references programmatically.
var semanticModel = document.GetSemanticModelAsync().Result;
var syntaxTree = semanticModel.SyntaxTree;
var methodDeclarations =
syntaxTree.GetRootAsync().Result.DescendantNodes().OfType<MethodDeclarationSyntax>().Where(m => m.Identifier.ValueText.Equals(criteria.SymbolName));
foreach(var methodDeclaration in methodDeclarations)
{
var node = semanticModel.GetDeclaredSymbol(methodDeclaration);
var references = SymbolFinder.FindReferencesAsync(node, solution).Result.ToList();
symbolReferences.AddRange(references);
}
For all the solutions, diagnostics returns a list of errors like System.string not found
, System.Object not found
and so on. As it was common across solutions, I ignored it.
Is there any reason why this could be happening? Any suggestions on where to look at or how to get this working?