Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Open .aar files with ReadWrite FileAccess #9737

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

dellis1972
Copy link
Contributor

Fixes #9735

Building a Maui app we end up with the following error

System.IO.IOException: The process cannot access the file 'C:\Users\rumar\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\xamarin.androidx.core\1.15.0.2\aar\androidx.core.core.aar' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   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)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Xamarin.Android.Tasks.FileResourceParser.Parse(String resourceDirectory, IEnumerable`1 additionalResourceDirectories, IEnumerable`1 aarLibraries, Dictionary`2 resourceMap) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs:line 82
   at Xamarin.Android.Tasks.GenerateRtxt.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateRtxt.cs:line 35
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

This is because we were using FileShare.ReadWrite in the FileResourceParser. Switch this out to use File.OpenRead
which uses FileShare.Read under the hood to open the file.

@jonathanpeppers jonathanpeppers merged commit 328b024 into main Jan 31, 2025
58 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/dellis1972/readwrite branch January 31, 2025 14:39
jonathanpeppers pushed a commit that referenced this pull request Jan 31, 2025
…leAccess (#9737)

Fixes: #9735

Building a Maui app we end up with the following error

   System.IO.IOException: The process cannot access the file 'C:\Users\rumar\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\xamarin.androidx.core\1.15.0.2\aar\androidx.core.core.aar' because it is being used by another process.
      at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
      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)
      at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
      at Xamarin.Android.Tasks.FileResourceParser.Parse(String resourceDirectory, IEnumerable`1 additionalResourceDirectories, IEnumerable`1 aarLibraries, Dictionary`2 resourceMap) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/FileResourceParser.cs:line 82
      at Xamarin.Android.Tasks.GenerateRtxt.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateRtxt.cs:line 35
      at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

This is because we were using `FileShare.ReadWrite` in the
`FileResourceParser`. Switch this out to use `File.OpenRead` which
uses `FileShare.Read` under the hood to open the file.
grendello added a commit that referenced this pull request Jan 31, 2025
* main:
  [Xamarin.Android.Build.Tasks] Don't Open .aar files with ReadWrite FileAccess (#9737)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.IO.IOException: The process cannot access the file
2 participants