diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/FileChangeTracker.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/FileChangeTracker.cs index ef40a9fc74c1a3f85061f0e680dfd29a08c0172d..e5de6fdc4596e7efa7f658522e1ff92fa2d457b4 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/FileChangeTracker.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/FileChangeTracker.cs @@ -96,7 +96,7 @@ public void StartFileChangeListeningAsync() _fileChangeService.AdviseFileChange(_filePath, FileChangeFlags, this, out var newCookie)); return newCookie; } - catch (Exception e) when (ShouldTrapException(e)) + catch (Exception e) when (ReportException(e)) { return null; } @@ -108,25 +108,17 @@ public void StartFileChangeListeningAsync() } } - private static bool ShouldTrapException(Exception e) + private static bool ReportException(Exception e) { - if (e is FileNotFoundException) + // If we got a PathTooLongException there's really nothing we can do about it; we will fail to read the file later which is fine + if (!(e is PathTooLongException)) { - // The IVsFileChange implementation shouldn't ever be throwing exceptions like this, but it's a - // transient file system issue (perhaps the file being deleted while we're changing subscriptions) - // and so there's nothing better to do. We'll still non-fatal to track the rate this is happening return FatalError.ReportWithoutCrash(e); } - else if (e is PathTooLongException) - { - // Nothing better we can do. We won't be able to open this file either, and thus we'll do our usual - // reporting of unopenable/missing files to the output window as usual. - return true; - } - else - { - return false; - } + + // We'll always capture all exceptions regardless. If we don't, then the exception is captured by our lazy and will be potentially rethrown from + // StopFileChangeListening or Dispose which causes all sorts of downstream problems. + return true; } public void StopFileChangeListening() @@ -155,7 +147,7 @@ public void StopFileChangeListening() Marshal.ThrowExceptionForHR( _fileChangeService.UnadviseFileChange(fileChangeCookie.Value)); } - catch (Exception e) when (ShouldTrapException(e)) + catch (Exception e) when (ReportException(e)) { } }