From 01406fff09cb5ae4581fa025e99796543693a633 Mon Sep 17 00:00:00 2001 From: Allison Chou Date: Wed, 14 Jun 2023 12:00:45 -0700 Subject: [PATCH 1/3] Don't try to create FileSystemWatcher in Razor scenarios --- .../EditAndContinueFeedbackDiagnosticFileProvider.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs index 6240fe711aab7..3f115d36bace3 100644 --- a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs +++ b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs @@ -39,7 +39,7 @@ internal sealed class EditAndContinueFeedbackDiagnosticFileProvider : IFeedbackD /// Watching the file is currently the only way to detect the feedback session. /// private readonly string _vsFeedbackSemaphoreFullPath; - private readonly FileSystemWatcher _vsFeedbackSemaphoreFileWatcher; + private readonly FileSystemWatcher? _vsFeedbackSemaphoreFileWatcher; private readonly int _vsProcessId; private readonly DateTime _vsProcessStartTime; @@ -65,6 +65,12 @@ public EditAndContinueFeedbackDiagnosticFileProvider( var vsFeedbackTempDir = Path.Combine(_tempDir, VSFeedbackSemaphoreDir); _vsFeedbackSemaphoreFullPath = Path.Combine(vsFeedbackTempDir, VSFeedbackSemaphoreFileName); + // Directory may not exist in scenarios such as Razor integration tests + if (!Directory.Exists(vsFeedbackTempDir)) + { + return; + } + _vsFeedbackSemaphoreFileWatcher = new FileSystemWatcher(vsFeedbackTempDir, VSFeedbackSemaphoreFileName); _vsFeedbackSemaphoreFileWatcher.Created += (_, _) => OnFeedbackSemaphoreCreatedOrChanged(); _vsFeedbackSemaphoreFileWatcher.Changed += (_, _) => OnFeedbackSemaphoreCreatedOrChanged(); From 3801cc8dea47884b0034f55bb7e0b2a5056f5d0a Mon Sep 17 00:00:00 2001 From: Allison Chou Date: Wed, 14 Jun 2023 12:07:08 -0700 Subject: [PATCH 2/3] Add condition --- .../EditAndContinueFeedbackDiagnosticFileProvider.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs index 3f115d36bace3..165f505af62d4 100644 --- a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs +++ b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs @@ -99,7 +99,9 @@ private string GetZipFilePath() => Path.Combine(Path.Combine(_tempDir, $"EnC_{_vsProcessId}", ZipFileName)); public IReadOnlyCollection GetFiles() - => new[] { GetZipFilePath() }; + => _vsFeedbackSemaphoreFullPath is null + ? Array.Empty() + : (IReadOnlyCollection)(new[] { GetZipFilePath() }); private void OnFeedbackSemaphoreCreatedOrChanged() { From dd2858e7d7d4a5f61dfe467b26dee728a642e8c5 Mon Sep 17 00:00:00 2001 From: Allison Chou Date: Wed, 14 Jun 2023 12:07:44 -0700 Subject: [PATCH 3/3] Add condition --- .../EditAndContinueFeedbackDiagnosticFileProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs index 165f505af62d4..670396231af7a 100644 --- a/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs +++ b/src/VisualStudio/Core/Def/EditAndContinue/EditAndContinueFeedbackDiagnosticFileProvider.cs @@ -99,7 +99,7 @@ private string GetZipFilePath() => Path.Combine(Path.Combine(_tempDir, $"EnC_{_vsProcessId}", ZipFileName)); public IReadOnlyCollection GetFiles() - => _vsFeedbackSemaphoreFullPath is null + => _vsFeedbackSemaphoreFileWatcher is null ? Array.Empty() : (IReadOnlyCollection)(new[] { GetZipFilePath() });