vscode-csharp
vscode-csharp copied to clipboard
Omnisharp failing due to `System.IO.IOException: The process cannot access the file ... because it is being used by another process`
Issue Description
When saving a C# file (/filesChanged
), Omnisharp fails due to a System.IO.IOException
, stating that it is being used by another process.
Steps to Reproduce
- Create a new project.
- Have Omnisharp set to format on save.
- Make changes to a C# file.
- Save or otherwise trigger the
/filesChanged
command.
Expected Behavior
The C# file should be formatted and saved.
Actual Behavior
The file does not get formatted, and the output log prints the log below.
Logs
OmniSharp log
[warn]: OmniSharp.Stdio.Host ************ Request ************ { "Type": "request", "Seq": 180, "Command": "/filesChanged", "Arguments": [ { "FileName": "d:\\Programming\\GithubRepos\\CsLorax\\LoraxTest\\LoraxTest.cs", "changeType": "Change" } ] } [fail]: OmniSharp.Stdio.Host ************ Response (0.7794ms) ************ { "Request_seq": 180, "Command": "/filesChanged", "Running": true, "Success": false, "Message": "\"System.IO.IOException: The process cannot access the file 'd:\\\\Programming\\\\GithubRepos\\\\CsLorax\\\\LoraxTest\\\\LoraxTest.cs' because it is being used by another process.\\r\\n at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)\\r\\n at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)\\r\\n at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)\\r\\n at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)\\r\\n at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)\\r\\n at System.IO.File.InternalReadAllText(String path, Encoding encoding)\\r\\n at System.IO.File.ReadAllText(String path)\\r\\n at OmniSharp.Roslyn.BufferManager.UpdateBufferAsync(Request request, Boolean isCreate) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn\\\\BufferManager.cs:line 49\"", "Body": null, "Seq": 3960, "Type": "response" }
C# log
Getting latest OmniSharp version information Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Environment information
VSCode version: 1.67.2 C# Extension: 1.25.0
Dotnet Information
.NET SDK (reflecting any global.json): Version: 6.0.201 Commit: ef40e6aa06Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.201\
Host (useful for support): Version: 6.0.3 Commit: c24d9a9c91
.NET SDKs installed: 5.0.406 [C:\Program Files\dotnet\sdk] 6.0.201 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions
Extension | Author | Version |
---|---|---|
autodocstring | njpwerner | 0.6.1 |
better-comments | aaron-bond | 3.0.0 |
better-cpp-syntax | jeff-hykin | 1.15.14 |
better-shellscript-syntax | jeff-hykin | 1.1.0 |
better-toml | bungcip | 0.3.2 |
blazorwasm-companion | ms-dotnettools | 1.1.0 |
copilot | GitHub | 1.24.6022 |
cpptools-themes | ms-vscode | 1.0.0 |
csharp | ms-dotnettools | 1.25.0 |
csharpextensions | jchannon | 1.3.1 |
dark-plus-material | vangware | 3.0.4 |
errorlens | usernamehw | 3.5.1 |
es7-react-js-snippets | dsznajder | 4.4.3 |
format-html-in-php | rifi2k | 1.7.0 |
html-preview-vscode | tht13 | 0.2.5 |
indent-rainbow | oderwat | 8.3.1 |
java | redhat | 1.6.0 |
JavaScriptSnippets | xabikos | 1.8.0 |
jshint | dbaeumer | 0.11.0 |
jupyter | ms-toolsai | 2022.4.1021342353 |
jupyter-keymap | ms-toolsai | 1.0.0 |
jupyter-renderers | ms-toolsai | 1.0.8 |
kotlin | fwcd | 0.2.26 |
Kotlin | mathiasfrohlich | 1.7.1 |
ksp-cfg-support | al2me6 | 0.2.1 |
lexurgy-syntax-highlighting | bigyihsuan9999 | 0.0.2 |
Lisp | mattn | 0.1.12 |
markdown-all-in-one | yzhang | 3.4.3 |
markdown-mermaid | bierner | 1.14.0 |
markdown-pdf | yzane | 1.4.4 |
markdown-preview-enhanced | shd101wyy | 0.6.3 |
material-theme | zhuangtongfa | 3.13.29 |
mayukaithemevsc | GulajavaMinistudio | 3.2.1 |
mermaid-markdown-syntax-highlighting | bpruitt-goddard | 1.2.3 |
noctis | liviuschera | 10.40.0 |
one-dark-pro-monokai-darker | eserozvataf | 1.1.0 |
one-dark-theme | mskelton | 1.14.2 |
one-monokai | azemoh | 0.5.0 |
tomoki1207 | 1.2.0 | |
php-debug | xdebug | 1.26.1 |
php-intellisense | zobo | 1.0.8 |
php-pack | xdebug | 1.0.3 |
prettify-json | mohsen1 | 0.0.3 |
python | ms-python | 2022.6.3 |
rainbow-csv | mechatroner | 2.4.0 |
rainbow-tags | voldemortensen | 0.4.1 |
red-one-dark-pro | giladgd | 1.5.0 |
remote-containers | ms-vscode-remote | 0.234.0 |
remote-ssh | ms-vscode-remote | 0.80.0 |
remote-ssh-edit | ms-vscode-remote | 0.80.0 |
remote-wsl | ms-vscode-remote | 0.66.3 |
rust | rust-lang | 0.7.8 |
rust-analyzer | rust-lang | 0.3.1075 |
rust-syntax | dustypomerleau | 0.6.0 |
semantic-rainbow | thertzlor | 1.0.5 |
shebang-snippets | rpinski | 0.1.4 |
sql-snippet | Miladfathy | 0.0.4 |
sql-snippets | sadeghpm | 0.0.4 |
syntax-highlight | peaceshi | 0.0.14 |
teppz | ofrades | 2.4.2 |
vsc-community-material-theme | Equinusocio | 1.4.4 |
vsc-material-theme | Equinusocio | 33.4.0 |
vsc-material-theme-icons | equinusocio | 2.3.1 |
vsc-moonrise-theme | odind | 0.2.2 |
vscode-antlr4 | mike-lischke | 2.3.0 |
vscode-color-identifiers-mode | MatthewNespor | 1.2.0 |
vscode-csharp-snippets | jorgeserrano | 1.1.0 |
vscode-dotnet-runtime | ms-dotnettools | 1.5.0 |
vscode-ebnf | OMKOV | 1.0.4 |
vscode-html-css | ecmel | 1.12.2 |
vscode-icons | vscode-icons-team | 11.12.0 |
vscode-intelephense-client | bmewburn | 1.8.2 |
vscode-java-debug | vscjava | 0.41.0 |
vscode-java-dependency | vscjava | 0.19.1 |
vscode-java-pack | vscjava | 0.22.4 |
vscode-java-test | vscjava | 0.35.0 |
vscode-JS-CSS-HTML-formatter | lonefy | 0.2.3 |
vscode-markdownlint | DavidAnson | 0.47.0 |
vscode-maven | vscjava | 0.35.2 |
vscode-mysql-client2 | cweijan | 5.3.7 |
vscode-nuget-package-manager | jmrog | 1.1.6 |
vscode-osgi | lgdd | 1.0.2 |
vscode-pull-request-github | GitHub | 0.42.0 |
vscode-pylance | ms-python | 2022.5.3 |
vscode-remote-extensionpack | ms-vscode-remote | 0.21.0 |
vscode-rusty-onedark | Jeraldson | 1.0.3 |
vscode-solution-explorer | fernandoescolar | 0.4.5 |
vscodeintellicode | VisualStudioExptTeam | 1.2.21 |
I have a similar problem, except that save on format
is not enabled in my case.
Any workarounds yet ?
I have the same issue, and as @DanteMarshal pointed out, I don't have format on save
enabled either.
But otherwise, the error message is exactly the same. I'm using .NET SDK Version: 6.0.307 Commit: 55b7c993a1
I also saw this issue that has been marked as completed but the error message from this one is slightly different.
My only solution right now is to use the Restart OmniSharp
command, but the error usually happens again soon after..
If anyone has a solution of info on this problem that would be fantastic :)