diff --git a/src/Features/Core/Portable/IncrementalCaches/SymbolTreeInfoIncrementalAnalyzerProvider.cs b/src/Features/Core/Portable/IncrementalCaches/SymbolTreeInfoIncrementalAnalyzerProvider.cs index 8eb20d5f909ed067c749e669e297658432d79fef..106bf039ffb9f8211a5a81cb825a2b7add0c1fe9 100644 --- a/src/Features/Core/Portable/IncrementalCaches/SymbolTreeInfoIncrementalAnalyzerProvider.cs +++ b/src/Features/Core/Portable/IncrementalCaches/SymbolTreeInfoIncrementalAnalyzerProvider.cs @@ -218,48 +218,52 @@ private async Task UpdateSymbolTreeInfoAsync(Project project, CancellationToken private async Task UpdateReferencesAync(Project project, CancellationToken cancellationToken) { - Compilation compilation = null; foreach (var reference in project.MetadataReferences.OfType()) { - compilation = await UpdateReferenceAsync(project, reference, compilation, cancellationToken).ConfigureAwait(false); + await UpdateReferenceAsync(project, reference, cancellationToken).ConfigureAwait(false); } } - private async Task UpdateReferenceAsync( - Project project, PortableExecutableReference reference, Compilation compilation, CancellationToken cancellationToken) + private async Task UpdateReferenceAsync( + Project project, PortableExecutableReference reference, CancellationToken cancellationToken) { var key = GetReferenceKey(reference); - if (key != null) + if (key == null) { - DateTime lastWriteTime; - if (!TryGetLastWriteTime(key, out lastWriteTime)) - { - // Couldn't get the write time. Just ignore this reference. - return compilation; - } + return; + } - MetadataInfo metadataInfo; - if (_metadataPathToInfo.TryGetValue(key, out metadataInfo) && metadataInfo.TimeStamp == lastWriteTime) - { - // We've already computed and cached the info for this reference. - return compilation; - } + DateTime lastWriteTime; + if (!TryGetLastWriteTime(key, out lastWriteTime)) + { + // Couldn't get the write time. Just ignore this reference. + return; + } - compilation = compilation ?? await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); - var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; - if (assembly != null) - { - var info = await SymbolTreeInfo.TryGetInfoForMetadataAssemblyAsync(project.Solution, assembly, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false); - metadataInfo = metadataInfo ?? new MetadataInfo(lastWriteTime, info, new HashSet()); + MetadataInfo metadataInfo; + if (_metadataPathToInfo.TryGetValue(key, out metadataInfo) && metadataInfo.TimeStamp == lastWriteTime) + { + // We've already computed and cached the info for this reference. + return; + } - // Keep track that this dll is referenced by this project. - metadataInfo.ReferencingProjects.Add(project.Id); + var compilationService = project.LanguageServices.GetService(); + var compilation = compilationService.CreateCompilation("TempAssembly", compilationService.GetDefaultCompilationOptions()) + .WithReferences(reference); - _metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo); - } + var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol; + if (assembly == null) + { + return; } - return compilation; + var info = await SymbolTreeInfo.TryGetInfoForMetadataAssemblyAsync(project.Solution, assembly, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false); + metadataInfo = metadataInfo ?? new MetadataInfo(lastWriteTime, info, new HashSet()); + + // Keep track that this dll is referenced by this project. + metadataInfo.ReferencingProjects.Add(project.Id); + + _metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo); } public override void RemoveProject(ProjectId projectId)