@@ -31,7 +31,7 @@ internal sealed partial class MiscellaneousFilesWorkspace : Workspace, IOpenText
3131 private readonly IThreadingContext _threadingContext ;
3232 private readonly IVsService < IVsTextManager > _textManagerService ;
3333 private readonly OpenTextBufferProvider _openTextBufferProvider ;
34- private readonly Lazy < IMetadataAsSourceFileService > _fileTrackingMetadataAsSourceService ;
34+ private readonly IMetadataAsSourceFileService _fileTrackingMetadataAsSourceService ;
3535
3636 private readonly ConcurrentDictionary < Guid , LanguageInformation > _languageInformationByLanguageGuid = [ ] ;
3737
@@ -47,24 +47,24 @@ internal sealed partial class MiscellaneousFilesWorkspace : Workspace, IOpenText
4747 /// </summary>
4848 private readonly Dictionary < string , ( ProjectId projectId , SourceTextContainer textContainer ) > _monikersToProjectIdAndContainer = [ ] ;
4949
50- private readonly Lazy < ImmutableArray < MetadataReference > > _metadataReferences ;
50+ private readonly ImmutableArray < MetadataReference > _metadataReferences ;
5151
5252 [ ImportingConstructor ]
5353 [ Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
5454 public MiscellaneousFilesWorkspace (
5555 IThreadingContext threadingContext ,
5656 IVsService < SVsTextManager , IVsTextManager > textManagerService ,
5757 OpenTextBufferProvider openTextBufferProvider ,
58- Lazy < IMetadataAsSourceFileService > fileTrackingMetadataAsSourceService ,
59- Composition . ExportProvider exportProvider )
60- : base ( VisualStudioMefHostServices . Create ( exportProvider ) , WorkspaceKind . MiscellaneousFiles )
58+ IMetadataAsSourceFileService fileTrackingMetadataAsSourceService ,
59+ VisualStudioWorkspace visualStudioWorkspace )
60+ : base ( visualStudioWorkspace . Services . HostServices , WorkspaceKind . MiscellaneousFiles )
6161 {
6262 _threadingContext = threadingContext ;
6363 _textManagerService = textManagerService ;
6464 _openTextBufferProvider = openTextBufferProvider ;
6565 _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService ;
6666
67- _metadataReferences = new ( ( ) => [ .. CreateMetadataReferences ( ) ] ) ;
67+ _metadataReferences = [ .. CreateMetadataReferences ( ) ] ;
6868
6969 _openTextBufferProvider . AddListener ( this ) ;
7070 }
@@ -122,10 +122,6 @@ public void RegisterLanguage(Guid languageGuid, string languageName, string scri
122122
123123 private IEnumerable < MetadataReference > CreateMetadataReferences ( )
124124 {
125- // VisualStudioMetadataReferenceManager construction requires the main thread
126- // TODO: Determine if main thread affinity can be removed: https://github.com/dotnet/roslyn/issues/77791
127- _threadingContext . ThrowIfNotOnUIThread ( ) ;
128-
129125 var manager = this . Services . GetService < VisualStudioMetadataReferenceManager > ( ) ;
130126 var searchPaths = VisualStudioMetadataReferenceManager . GetReferencePaths ( ) ;
131127
@@ -265,7 +261,7 @@ private void AttachToDocument(string moniker, ITextBuffer textBuffer)
265261 {
266262 _threadingContext . ThrowIfNotOnUIThread ( ) ;
267263
268- if ( _fileTrackingMetadataAsSourceService . Value . TryAddDocumentToWorkspace ( moniker , textBuffer . AsTextContainer ( ) , out var _ ) )
264+ if ( _fileTrackingMetadataAsSourceService . TryAddDocumentToWorkspace ( moniker , textBuffer . AsTextContainer ( ) , out var _ ) )
269265 {
270266 // We already added it, so we will keep it excluded from the misc files workspace
271267 return ;
@@ -286,24 +282,20 @@ private void AttachToDocument(string moniker, ITextBuffer textBuffer)
286282 /// </summary>
287283 private ProjectInfo CreateProjectInfoForDocument ( string filePath )
288284 {
289- // Potential calculation of _metadataReferences requires being on the main thread
290- // TODO: Determine if main thread affinity can be removed: https://github.com/dotnet/roslyn/issues/77791
291- _threadingContext . ThrowIfNotOnUIThread ( ) ;
292-
293285 // This should always succeed since we only got here if we already confirmed the moniker is acceptable
294286 var languageInformation = TryGetLanguageInformation ( filePath ) ;
295287 Contract . ThrowIfNull ( languageInformation ) ;
296288
297289 var checksumAlgorithm = SourceHashAlgorithms . Default ;
298290 var fileLoader = new WorkspaceFileTextLoader ( Services . SolutionServices , filePath , defaultEncoding : null ) ;
299291 return MiscellaneousFileUtilities . CreateMiscellaneousProjectInfoForDocument (
300- this , filePath , fileLoader , languageInformation , checksumAlgorithm , Services . SolutionServices , _metadataReferences . Value ) ;
292+ this , filePath , fileLoader , languageInformation , checksumAlgorithm , Services . SolutionServices , _metadataReferences ) ;
301293 }
302294
303295 private void DetachFromDocument ( string moniker )
304296 {
305297 _threadingContext . ThrowIfNotOnUIThread ( ) ;
306- if ( _fileTrackingMetadataAsSourceService . Value . TryRemoveDocumentFromWorkspace ( moniker ) )
298+ if ( _fileTrackingMetadataAsSourceService . TryRemoveDocumentFromWorkspace ( moniker ) )
307299 {
308300 return ;
309301 }
0 commit comments