Occasionally when running unit tests with coverage stats an exception is thrown because the coverage.xml file from the previous run is still being accessed.
Expected behaviour: Tests run correctly and latest coverage details get shown
Actual behaviour: Exception is thrown
Exception output:
SharpDevelop Version : 5.0.0.4755-c848dc28
.NET Version : 4.5.50938
OS Version : Microsoft Windows NT 6.1.7601 Service Pack 1
Current culture : English (United Kingdom) (en-GB)
Running under WOW6432, processor architecture: x86-64
Working Set Memory : 280276kb
GC Heap Memory : 119346kb
Exception thrown:
System.AggregateException: One or more errors occurred. ---> System.IO.IOException: The process cannot access the file 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\TestSimSys2\OpenCover\coverage.xml' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at ICSharpCode.SharpDevelop.FileSystem.Delete(FileName path)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.RemoveExistingCodeCoverageResultsFile(String fileName)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.CreateOpenCoverApplication(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__1(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.ModifyProcessStartInfoBeforeRun(ProcessStartInfo startInfo, IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.Start(IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestRunnerBase.RunAsync(IEnumerable`1 selectedTests, IProgress`1 progress, TextWriter output, CancellationToken cancellationToken)
at ICSharpCode.UnitTesting.Frameworks.TestExecutionManager.<RunTestsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.UnitTesting.SDTestService.<RunTestsAsync>d__0.MoveNext()
--- End of inner exception stack trace ---
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.AfterTestsRunTask(Task task, CodeCoverageResultsReader coverageResultsReader)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__2(Task t)
at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) System.IO.IOException: The process cannot access the file 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\TestSimSys2\OpenCover\coverage.xml' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at ICSharpCode.SharpDevelop.FileSystem.Delete(FileName path)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.RemoveExistingCodeCoverageResultsFile(String fileName)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.CreateOpenCoverApplication(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__1(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.ModifyProcessStartInfoBeforeRun(ProcessStartInfo startInfo, IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.Start(IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestRunnerBase.RunAsync(IEnumerable`1 selectedTests, IProgress`1 progress, TextWriter output, CancellationToken cancellationToken)
at ICSharpCode.UnitTesting.Frameworks.TestExecutionManager.<RunTestsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.UnitTesting.SDTestService.<RunTestsAsync>d__0.MoveNext()<---
---- Recent log messages:
20:08:23.612 [29] DEBUG - Received command BuildDone
20:08:23.612 [29] INFO - Finished building SimSys2, success=True
20:08:23.612 [29] INFO - Start building TestSimSys2
20:08:23.613 [14] DEBUG - Setting property CurrentSolutionConfigurationContents to '<SolutionConfiguration><ProjectConfiguration Project="{F476B7C7-7C17-4142-A82B-F08F2E632052}">Debug|x86</ProjectConfiguration><ProjectConfiguration Project="{C543E22E-E9FA-46DB-B19F-9B8A9890C4C6}">Debug|AnyCPU</ProjectConfiguration><ProjectConfiguration Project="{F7125EFF-A14C-4E10-BEB6-B64ADA561390}">Debug|AnyCPU</ProjectConfiguration><ProjectConfiguration Project="{2C69D540-2D4C-4110-B929-A04D6DA598B5}">Debug|x86</ProjectConfiguration><ProjectConfiguration Project="{C00E235C-810C-4F03-A2B0-4BBC498E0D07}">Debug|AnyCPU</ProjectConfiguration></SolutionConfiguration>'
20:08:23.613 [14] DEBUG - Setting property SolutionDir to 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\'
20:08:23.613 [14] DEBUG - Setting property SolutionExt to '.sln'
20:08:23.613 [14] DEBUG - Setting property SolutionFileName to 'SimSys2.sln'
20:08:23.613 [14] DEBUG - Setting property SolutionName to 'SimSys2'
20:08:23.613 [14] DEBUG - Setting property SolutionPath to 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\SimSys2.sln'
20:08:23.614 [29] DEBUG - Received command ReportEvent
20:08:23.642 [29] DEBUG - Received command ReportEvent
20:08:23.646 [29] DEBUG - Received command ReportEvent
20:08:23.665 [29] DEBUG - Received command ReportEvent
20:08:23.665 [29] DEBUG - Received command ReportEvent
20:08:23.667 [29] DEBUG - Received command ReportEvent
20:08:23.667 [29] DEBUG - Received command ReportEvent
20:08:23.771 [29] DEBUG - Received command ReportEvent
20:08:23.777 [29] DEBUG - Received command ReportEvent
20:08:23.785 [29] DEBUG - Received command ReportEvent
20:08:23.785 [29] DEBUG - Received command ReportEvent
20:08:23.785 [29] DEBUG - Received command BuildDone
20:08:23.786 [29] INFO - Finished building TestSimSys2, success=True
20:08:23.787 [16] ERROR -
--> Exception:
System.AggregateException: One or more errors occurred. ---> System.IO.IOException: The process cannot access the file 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\TestSimSys2\OpenCover\coverage.xml' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at ICSharpCode.SharpDevelop.FileSystem.Delete(FileName path)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.RemoveExistingCodeCoverageResultsFile(String fileName)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.CreateOpenCoverApplication(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__1(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.ModifyProcessStartInfoBeforeRun(ProcessStartInfo startInfo, IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.Start(IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestRunnerBase.RunAsync(IEnumerable`1 selectedTests, IProgress`1 progress, TextWriter output, CancellationToken cancellationToken)
at ICSharpCode.UnitTesting.Frameworks.TestExecutionManager.<RunTestsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.UnitTesting.SDTestService.<RunTestsAsync>d__0.MoveNext()
--- End of inner exception stack trace ---
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.AfterTestsRunTask(Task task, CodeCoverageResultsReader coverageResultsReader)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__2(Task t)
at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) System.IO.IOException: The process cannot access the file 'C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\TestSimSys2\OpenCover\coverage.xml' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at ICSharpCode.SharpDevelop.FileSystem.Delete(FileName path)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.RemoveExistingCodeCoverageResultsFile(String fileName)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.CreateOpenCoverApplication(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.CodeCoverage.RunTestWithCodeCoverageCommand.<>c__DisplayClass3.<Run>b__1(ProcessStartInfo startInfo, IEnumerable`1 tests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.ModifyProcessStartInfoBeforeRun(ProcessStartInfo startInfo, IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestProcessRunnerBase.Start(IEnumerable`1 selectedTests)
at ICSharpCode.UnitTesting.TestRunnerBase.RunAsync(IEnumerable`1 selectedTests, IProgress`1 progress, TextWriter output, CancellationToken cancellationToken)
at ICSharpCode.UnitTesting.Frameworks.TestExecutionManager.<RunTestsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.UnitTesting.SDTestService.<RunTestsAsync>d__0.MoveNext()<---
20:08:23.787 [1] DEBUG - ActiveContentChanged to ICSharpCode.SharpDevelop.Gui.ErrorListPad
20:08:23.787 [16] WARN - Stack trace of last exception log:
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at ICSharpCode.SharpDevelop.Logging.SDMessageService.ShowException(Exception ex, String message)
at ICSharpCode.SharpDevelop.SharpDevelopExtensions.<FireAndForget>b__0(Task t)
at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
---- Post-error application state information:
Installed 3rd party AddIns:
ProjectService.CurrentSolution: [Solution C:\Users\Grahame\Documents\Source Code\C#\SimSystemII\SimSys2.sln with 5 projects]
ProjectService.CurrentProject: [CSharpProject: SimSys2]
Workbench.ActiveContent: System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at ICSharpCode.SharpDevelop.DispatcherMessageLoop.VerifyAccess()
at ICSharpCode.SharpDevelop.Workbench.WpfWorkbench.get_ActiveContent()
at ICSharpCode.SharpDevelop.Workbench.WorkbenchStartup.<InitializeWorkbench>b__0()
at ICSharpCode.Core.ApplicationStateInfoService.GetCurrentApplicationStateInfo()