Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

System.IO.IOException: The process cannot access the file because it is being used by another process

Open Beginner friendly
#824 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
build-system

Research direction

Review src/LibraryManager.Contracts/FileHelpers.cs around the CopyFileAsync method at lines 142-160, especially the source FileStream opening. Reproduce the concurrent-library-copy scenario described in the issue and verify that multiple projects can copy the same cached file without the IOException while preserving normal copy behavior.

Written by the indexing model from the issue text.

Description

Describe the bug

We have a solution containing multiple projects that use Microsoft.Web.LibraryManager.Build for restoring JavaScipt libraries. Some of these projects reference the same library from the same provider. We have multiple build servers, and on our more recent, faster build server we noticed builds are regularly failing with error messages of the following kind:

C:\nuget\microsoft.web.librarymanager.build\3.0.71\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error : Error during copying file System.IO.IOException: The process cannot access the file 'C:\Users\[username]\AppData\Local\.librarymanager\cache\jsdelivr\jquery\3.7.1\dist\jquery.min.js' because it is being used by another process.
C:\nuget\microsoft.web.librarymanager.build\3.0.71\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error :    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
C:\nuget\microsoft.web.librarymanager.build\3.0.71\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error :    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
C:\nuget\microsoft.web.librarymanager.build\3.0.71\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error :    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
C:\nuget\microsoft.web.librarymanager.build\3.0.71\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error :    at Microsoft.Web.LibraryManager.Contracts.FileHelpers.<CopyFileAsync>d__4.MoveNext()

This is the method this exception occurs in:
https://github.com/aspnet/LibraryManager/blob/07b204fe119d2ab9cf51ce700a690fbb434417ca/src/LibraryManager.Contracts/FileHelpers.cs#L142-L160

The problematic line ist probably the following:

using FileStream sourceStream = File.Open(sourceFile, FileMode.Open, FileAccess.Read);

I would suggest changing it as follows:

using FileStream sourceStream = File.Open(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read);

This should allow multiple processes to access the same file at the same time.

While at it, a Task.Delay between the first and second iteration might also help to reduce the flakiness.

Additional context

Microsoft.Web.LibraryManager.Build, Version 3.0.71

Dominant language
C#
Stars
485
Forks
92
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aspnet/LibraryManager

All issues in aspnet/LibraryManager

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.