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

Creating .NET MAUI Project sometimes causes error *.png is being used by another process #25374

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Oct 18, 2024

Fixes #25207
Context
dotnet/android-tools#245
dotnet/android#9409

So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build.

So lets try a few things to fix this.

  1. Move the Resizetizer output for a DTB into the android $(IntermediateOutputPath)designtime folder. This will keep the DTB files completely separate. This should prevent clashes.
  2. Add some retry code to the SkiaSharpTools.Save method. This will catch UnauthorizedAccessException exceptions as well as specific IOException types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again.

Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior.

  1. DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS. Integer, controls the number of times we try to write the file. The default is 10.
  2. DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).

… by another process

Fixes dotnet#25207
Context
dotnet/android-tools#245
dotnet/android#9409

So there is a problem where the design time builds (DTB) of android sometimes
lock files. This can happen when two processes try to write to the same
file. This is not a great experience for our users as it just fails the build.

So lets try a few things to fix this.

1. Move the Resizetizer output for a DTB into the android
`$(IntermediateOutputPath)designtime` folder. This will keep the DTB files
completely separate. This should prevent clashes.
2. Add some retry code to the `SkiaSharpTools.Save` method. This will catch
`UnauthorizedAccessException` exceptions as well as specific `IOException` types
(Access Denied and Sharing Violation). This will allow us to catch when this happens
and retry the write. There is a small delay before attempting to write the file
again.

Note these code uses the Identical code as we are going to use in Android.
We have introduced two new environment variables which can be used to
control the new behavior.

1. `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`. Integer, controls the number of times
we try to write the file. The default is 10.
2. `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`. Integer, controls the delay in
milliseconds between retry attempts.  Default is 1000ms (or 1 second).
@dellis1972 dellis1972 requested a review from a team as a code owner October 18, 2024 10:29
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.

Creating .NET MAUI Project sometimes causes error *.png is being used by another process
1 participant