From 0c36876d4f5cb8a8fd0ffff5cb12bbbe819949ff Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Wed, 15 Jun 2016 17:16:39 -0700 Subject: [PATCH] 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 e4b9d9ea51271..6000726900224 100644 --- a/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs +++ b/src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs @@ -362,7 +362,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);