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

Intermittent Problem with Preferences on Windows #27167

Open
david-maw opened this issue Jan 16, 2025 · 0 comments
Open

Intermittent Problem with Preferences on Windows #27167

david-maw opened this issue Jan 16, 2025 · 0 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info essentials-preferences platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@david-maw
Copy link

Description

I get an intermittent IOException failure ("The process cannot access the file '...\Settings\preferences.dat' because it is being used by another process") trying to set a preference while exiting a MAUI program, probably as a result of a Window.Deactivated event. I have not been able to reproduce it in a simple test case, but it happens from time to time in my complex (about 16k lines of C# and XAML) app. I've added a link to the app repository below in case you want to look at the code.

Here's what the failure looks like, if you want me to collect more or different information next time it happens, I can.

System.IO.IOException
  HResult=0x80070020
  Message=The process cannot access the file 'C:\Users\david\AppData\Roaming\Microsoft\D9049CD2-5037-432D-BC7E-2E2FB39EBA1C\Settings\preferences.dat' because it is being used by another process.
  Source=System.Private.CoreLib
  StackTrace:
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.File.Create(String path)
   at Microsoft.Maui.Storage.UnpackagedPreferencesImplementation.Save()
   at Microsoft.Maui.Storage.UnpackagedPreferencesImplementation.Set[T](String key, T value, String sharedName)
   at Microsoft.Maui.Storage.PreferencesImplementation.Set[T](String key, T value, String sharedName)
   at Microsoft.Maui.Storage.Preferences.Set(String key, Boolean value, String sharedName)
   at Microsoft.Maui.Storage.Preferences.Set(String key, Boolean value)
   at DivisiBill.Services.AppSettings.set_MealSavedToFile(Boolean value) in H:\Develop\Phone\DivisiBill\DivisiBill\Services\AppSettings.cs:line 77
   at DivisiBill.Models.Meal.SaveToFile() in H:\Develop\Phone\DivisiBill\DivisiBill\Models\Meal.cs:line 1211
   at DivisiBill.Models.Meal.<SaveToFileAsync>b__89_0() in H:\Develop\Phone\DivisiBill\DivisiBill\Models\Meal.cs:line 1178
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

Steps to Reproduce

Itt's not reproducible to order.

Link to public reproduction project repository

https://github.com/david-maw/DivisiBill.git

Version with bug

9.0.21 SR2.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.93 SR9.3

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

No

Relevant log output

@david-maw david-maw added the t/bug Something isn't working label Jan 16, 2025
@StephaneDelcroix StephaneDelcroix added area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info essentials-preferences labels Jan 16, 2025
@StephaneDelcroix StephaneDelcroix added this to the Backlog milestone Jan 16, 2025
@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info essentials-preferences platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants