dotnet / dotnet/project-system
Roslyn symbol resolution fails after unloading and re-loading an SDK-style project.
- Dominant language
- C#
- Stars
- 1k
- Forks
- 415
- PR merge metrics
- No merged PRs in 30d
Description
In VS2017 15.9.11, I use the shell interfaces to programmatically unload and reload a C# project, and after the reload, Roslyn symbol resolution does not work. Inserting a delay (of up to 60 seconds) doesn't help.
Interestingly, this behavior is NOT observed with a non-SDK-style project. After unloading and re-loading the project, Roslyn is able to immediately resolve symbols.
The following project is all that is needed to see the failure:
```
net45
```
Use this code to resolve/unload/reload/resolve again:
```
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService();
var project = workspace.CurrentSolution.Projects.Single();
var compilation = ThreadHelper.JoinableTaskFactory.Run(async () => await project.GetCompilationAsync());
// Symbol resolves here.
//
var symbol = compilation.GetSpecialType(SpecialType.System_Int32);
var solution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
solution.GetProjectOfUniqueName(project.FilePath, out var hierarchy);
var projectId = solution.GetProjectIdGuid(hierarchy);
solution.UnloadProject(hierarchy);
solution.ReloadProject(projectId);
project = workspace.CurrentSolution.Projects.Single();
compilation = ThreadHelper.JoinableTaskFactory.Run(async () => await project.GetCompilationAsync());
// This returns null.
//
var symbol = compilation.GetSpecialType(SpecialType.System_Int32);
```
If you repeat the above on a from-scratch C# application that is NOT SDK-style, then you will see the above symbol resolution work just fine -- before and after the re-load.
It "feels" like Roslyn is waiting for something to "kick" it after an unload/reload cycle.
Very interested in this because we have a critical need to be able to unload a project do some work on the project file, reload it, and do some Roslyn transforms.
Thanks very much in advance.
Contributor guide
Assessment
This issue has not been assessed yet.