I am using roslyn in .NET Core 3.1 project and it is parsing a ASP.NET solution. The ASP.NET solution is calling the function MyTestMethod which is located in a .Net FW 4.6.2 referenced project. When running the following code for the function it does not return the location of the reference in the ASP.NET solution. However if I call the same function e.g. in a test project the location is successfully detected.
var symbol = semanticModel.GetDeclaredSymbol(node);
var references = SymbolFinder.FindReferencesAsync(symbol, solution).Result;
Could this problem be related to .net core being used with Roslyn? Any suggestions how I could test this further to narrow the cause of the problem?
In case it matters I am also using Buildalyzer.Workspaces in the Roslyn project.
[UPDATE] I am getting the following errors based on the Diagnostics but I am not sure if it's affecting the parsing of the references because I am getting this error also for the reference in the test project which works.
C:\root\MySolution\MyBllRefProject\Bll.cs(7,14): error CS0234: The type or namespace name 'MyNamespace' does not exist in the namespace 'MyAssembly' (are you missing an assembly reference?)
C:\root\MySolution\MyBllRefProject\OtherLogic.cs(629,32): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
C:\root\MySolution\MyBllRefProject\OtherLogic.cs(629,25): error CS0012: The type 'Action<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
C:\root\MySolution\MyBllRefProject\Config\AutoMapperBootstrap.cs(17,20): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
C:\root\MySolution\MyBllRefProject\DAL.cs(265,29): error CS0103: The name 'SQLHelper' does not exist in the current context
C:\root\MySolution\MyBllRefProject\DAL.cs(296,29): error CS0103: The name 'SQLHelper' does not exist in the current context
This is how the compilation is created (simplified)
var workspace = new AnalyzerManager(Solution).GetWorkspace();
var solution = workspace.CurrentSolution;
foreach (var file in p.Documents)
{
// Get syntax tree for file
var tree = file.GetSyntaxTreeAsync().Result;
// Get root of syntax tree
var root = (CompilationUnitSyntax)tree.GetRoot();
// Get project compilation for symbolic relationship in assembly
var compilation = p.GetCompilationAsync().Result;
// Get semantic model based on project compilation and the current document tree
var semanticModel = compilation.GetSemanticModel(tree);
// Get all methods from the file
var methodReferences = GetMethodReferences(solution, semanticModel, file, tree);
// do some more stuff
}