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

Merged
merged 4 commits into from
Dec 6, 2024

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 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).

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dellis1972
Copy link
Contributor Author

I can't see where the issues with CI are? everything seems to be timing out?

@mattleibow mattleibow added the area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer label Nov 13, 2024
@dellis1972 dellis1972 force-pushed the Issue25207 branch 2 times, most recently from aec6727 to a1114c1 Compare November 29, 2024 13:49
@dellis1972
Copy link
Contributor Author

@mattleibow @Redth any chance we can get this in? It might help with certain build issues

@rmarinho
Copy link
Member

rmarinho commented Dec 4, 2024

ups sorry didn t saw you just force pushed, I rebased again the android was hanging the 1st run taking more than 1h. lets see if it was a fluke

mattleibow
mattleibow previously approved these changes Dec 4, 2024
@PureWeen PureWeen added this to the .NET 9 SR2 milestone Dec 4, 2024
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… 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
Copy link
Contributor Author

looks like template tests are all failing https://dev.azure.com/xamarin/public/_build/results?buildId=129895&view=logs&jobId=8f6de8db-3d66-58dc-07d7-4a92e80cdb05&j=f3581e0c-6e47-5bad-9d98-3a98bd10977c&t=26132a5a-2e4c-526a-ae3b-42bdc526a803

Whats the best way to run this locally? I've tried looking at the run logs but they are corrupt ("There was an exception while reading the log file: Unable to read beyond the end of the stream.") .

@mattleibow mattleibow merged commit 31bfbcc into dotnet:main Dec 6, 2024
105 checks passed
@dellis1972 dellis1972 deleted the Issue25207 branch December 6, 2024 07:55
@samhouts samhouts added fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release!
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

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