Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MSBuild project to solution and apply the change to Roslyn workspace as a unit #2314

Merged

Conversation

dmgonch
Copy link
Contributor

@dmgonch dmgonch commented Dec 21, 2021

I often hit 'Failed to add project to workspace: ' error in OmniSharp log when opening one of internal projects. I only see this issue on Linux (Ubuntu 20.04) and not on Windows. I always have omnisharp.enableMsBuildLoadProjectsOnDemand set to "true". The problem occurs often but not all the time.

In both success and failure cases I see the following sequence of events (shortened to highlight only important parts):

[info]: OmniSharp.MSBuild.ProjectManager
	Queue project update for '/home/<path_to_project>/ProjectName.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
	Loading project: /home/<path_to_project>/ProjectName.csproj
[dbug]: OmniSharp.Stdio.Host
        ************ Request ************
{
  "Type": "request",
  "Seq": 7,
  "Command": "/filesChanged",
  "Arguments": [
    {
      "FileName": "/home/<path_to_project>/obj/Debug/net6.0/linux-x64/ProjectName.AssemblyInfo.cs",
      "changeType": "Change"
    }
  ]
}
[dbug]: OmniSharp.Roslyn.BufferManager
        Adding transient file for /home/<path_to_project>/obj/Debug/net6.0/linux-x64/ProjectName.AssemblyInfo.cs
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/home/<path_to_project>/ProjectName.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/home/<path_to_project>/ProjectName.csproj'

In the case of the failure though the sequence is followed by:

[fail]: OmniSharp.MSBuild.ProjectManager
	Failed to add project to workspace: '/home/<path_to_project>/ProjectName.csproj'
...
[fail]: OmniSharp.MSBuild.ProjectManager
	Could not locate project in workspace: /home/<path_to_project>/ProjectName.csproj

The documentation for "bool Workspace.TryApplyChanges(Solution newSolution)" states: “… The specified solution must be one that originated from this workspace. If it is not, or the workspace has been updated since the solution was obtained from the workspace, then this method returns false …"

ProjectManager.AddProject clearly passes the solution that is originated from the same workspace. Therefore, the workspace somehow gets changed b/w adding the project to the solution and applying the changes to the workspace. The theory is that the file change notification received for ProjectName.AssemblyInfo.cs causes the workspace change in ProjectManager.OnDirectoryFileChanged. Thus, the lock added around these two places. My testing shows that the change does address the issue I'm seeing.

@dmgonch
Copy link
Contributor Author

dmgonch commented Jan 6, 2022

@filipw, @JoeRobich, appreciate if you could take a look.

@JoeRobich JoeRobich self-requested a review January 11, 2022 22:01
Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JoeRobich JoeRobich merged commit 683a4fe into OmniSharp:master Jan 20, 2022
@dmgonch dmgonch deleted the dev/AddProjectToWorkspaceUnderLockPR branch January 20, 2022 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants