Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#824 1 bình luận 3 reaction 0 người được giao Xem trên GitHub

@brecht-yperman-uz đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #830 của @brecht-yperman-uz — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
build-system

Hướng nghiên cứu

Xem xét src/LibraryManager.Contracts/FileHelpers.cs xung quanh phương thức CopyFileAsync ở các dòng 142-160, đặc biệt là việc mở FileStream nguồn. Tái hiện kịch bản sao chép thư viện đồng thời được mô tả trong issue và xác minh rằng nhiều dự án có thể sao chép cùng một tệp đã được lưu trong bộ nhớ đệm mà không xảy ra IOException, đồng thời vẫn duy trì hành vi sao chép thông thường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C#
Star
485
Fork
92
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aspnet/LibraryManager

Tất cả issue của aspnet/LibraryManager

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.