From a4f73e449e54432a669092f32ed2a289a29a87dc Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Fri, 30 Aug 2024 20:16:23 -0700 Subject: [PATCH] Add NFW tracking to Solution.RemoveProjectReference Will help find underlying issue for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2136005 CPS has a system to catch exceptions from code they call into and have created this bug with a callstack and essentially no additional information about the exception being thrown. The hope here is that our reporting system will give us more actionable data. --- .../Portable/Workspace/Solution/Solution.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index df2751dc871ed..796fa8e99cf79 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; @@ -626,16 +627,23 @@ public Solution AddProjectReferences(ProjectId projectId, IEnumerableThe solution does not contain . public Solution RemoveProjectReference(ProjectId projectId, ProjectReference projectReference) { - if (projectReference == null) - throw new ArgumentNullException(nameof(projectReference)); + try + { + if (projectReference == null) + throw new ArgumentNullException(nameof(projectReference)); - CheckContainsProject(projectId); + CheckContainsProject(projectId); - var oldProject = GetRequiredProjectState(projectId); - if (!oldProject.ProjectReferences.Contains(projectReference)) - throw new ArgumentException(WorkspacesResources.Project_does_not_contain_specified_reference, nameof(projectReference)); + var oldProject = GetRequiredProjectState(projectId); + if (!oldProject.ProjectReferences.Contains(projectReference)) + throw new ArgumentException(WorkspacesResources.Project_does_not_contain_specified_reference, nameof(projectReference)); - return WithCompilationState(CompilationState.RemoveProjectReference(projectId, projectReference)); + return WithCompilationState(CompilationState.RemoveProjectReference(projectId, projectReference)); + } + catch (Exception ex) when (FatalError.ReportAndPropagate(ex)) + { + throw ExceptionUtilities.Unreachable(); + } } ///