From 4f5fc89e8f6401d9d43e330cb0816e9b35407a5c Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 20 Aug 2011 17:48:57 +0200 Subject: [PATCH] Handle FileNotFoundException when file gets deleted/renamed while a background parse operation for that file is starting. --- .../Src/Services/ParserService/ParserService.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs index 433a9ab7b8..dfa5a7ed72 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs @@ -406,7 +406,20 @@ namespace ICSharpCode.SharpDevelop if (fileContent == null) { // GetParseableFileContent must not be called inside any lock // (otherwise we'd risk deadlocks because GetParseableFileContent must invoke on the main thread) - fileContent = GetParseableFileContent(fileName); + try { + fileContent = GetParseableFileContent(fileName); + } catch (System.Reflection.TargetInvocationException ex) { + // It is possible that the file gets deleted/becomes inaccessible while a background parse + // operation is enqueued, so we have to handle IO exceptions. + if (ex.InnerException is IOException || ex.InnerException is UnauthorizedAccessException) + return null; + else + throw; + } catch (IOException) { + return null; + } catch (UnauthorizedAccessException) { + return null; + } } ITextBufferVersion fileContentVersion = fileContent.Version;