From 5d25d153277b4442492278b6e20a5d0986a39a43 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Wed, 15 Jun 2016 20:33:41 -0700 Subject: [PATCH 1/2] Merge pull request #12041 from heejaechang/buildsyncrace found one more case where documentId can be null --- ...gnosticIncrementalAnalyzer_IncrementalAnalyzer.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs index 83ed92840c7e8..9096e1b4a7b03 100644 --- a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs +++ b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs @@ -361,7 +361,17 @@ private void RaiseProjectDiagnosticsCreated(Project project, StateSet stateSet, foreach (var documentId in newAnalysisResult.DocumentIds) { var document = project.GetDocument(documentId); - Contract.ThrowIfNull(document); + if (document == null) + { + // it can happen with build synchronization since, in build case, + // we don't have actual snapshot (we have no idea what sources out of proc build has picked up) + // so we might be out of sync. + // example of such cases will be changing anything about solution while building is going on. + // it can be user explict actions such as unloading project, deleting a file, but also it can be + // something project system or roslyn workspace does such as populating workspace right after + // solution is loaded. + continue; + } RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.NonLocal, oldAnalysisResult, newAnalysisResult, raiseEvents); From 947e008fd3ad6584a39f82cf814333a91cf6e773 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Fri, 17 Jun 2016 13:59:55 -0700 Subject: [PATCH 2/2] prevent VS from crashing if VS got shutdown while build error reporting is in progress. --- .../SolutionCrawler/SolutionCrawlerRegistrationService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs index 3e668c0a7d1a5..d3d89522bc543 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs @@ -91,7 +91,10 @@ public void Reanalyze(Workspace workspace, IIncrementalAnalyzer analyzer, IEnume var coordinator = default(WorkCoordinator); if (!_documentWorkCoordinatorMap.TryGetValue(workspace, out coordinator)) { - throw new ArgumentException("workspace"); + // this can happen if solution crawler is already unregistered from workspace. + // one of those example will be VS shutting down so roslyn package is disposed but there is a pending + // async operation. + return; } // no specific projects or documents provided