Open touchofevil-dev opened 4 weeks ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Could you create a small reproduction sample with how you've implemented this?
Based on what you've written, I'm not sure if this is a MAUI UI issue yet.
This feels like a threading issue, but I'm not sure if this is related to a bug in MAUI, something in your code, something with WinUI, or something else.
Could you create a small reproduction sample with how you've implemented this?
Yes I have added the same in the issue. Updated reproduction steps too.
Based on what you've written, I'm not sure if this is a MAUI UI issue yet.
If you use File.WriteAllTextAsync and don't navigate with the shell, does that work?
I'm unsure which thread that relay command is run on. If you run the Shell.Current.GoTo command on the UI Dispatcher thread, does that work?
This feels like a threading issue, but I'm not sure if this is related to a bug in MAUI, something in your code, something with WinUI, or something else.
Yes even I wasn't sure, however the only time I faced this issue was when navigating. All other calls work well, so I have filed it here as a starting point. Another weird bit was I am only facing it on that particular screen (my assumption being due to file I/O operation only being on that screen). Navigation from other screens without file I/O doesn't seem to throw any exception.
Just to be clear, the navigation itself works from UI perspective, so on UI you'd actually see the screen you navigated to, however in the background you'd also get this exception.
@PureWeen What do you think?
Verified this issue with Visual Studio 17.11.0 Preview 2.0 & 17.10.1 (8.0.40&8.0.21&8.0.3). Not repro on Windows platform with sample project.
Verified the same on another machine to rule out for machine specific issues. Able to reproduce using provided project.
Also tried using VS 17.10.2 which is a released version.
Note: I have added empty catch block in the sample project so you'll need to put debugger breakpoint on catch block of SettingsVM.cs
file.
Attaching screenshot:
Description
I have a windows MAUI app. As part of this app, I update contents of a file. I am using MVVM pattern with CommunityToolkit.MVVM. I have below code snippets.
SettingsVM (Inherits from ObservableObject)
SettingsManager
This seems to throw below exception.
However, when I replace my code of SettingsManager to its sync version, I do not get that exception.
SettingsManager
I had this app in dotnet 7 and upgraded this to dotnet 8, and I am able to reproduce this behavior on both the versions. While the exception is being thrown on navigation, it somehow seems to be linked to file writing, since if I comment out the actual file writing or if I use the sync version it doesn't seem to throw any exception.
System Details: Dotnet version - 8.0.301 Visual Studio - 17.10.1 MAUI workload - maui-windows 8.0.21/8.0.100 SDK 8.0.300, VS 17.10.34928.147 Target framework -net8.0-windows10.0.19041.0
Packages: (on .net 8) Microsoft.Maui.Controls - 8.0.40 Microsoft.Maui.Controls.Compatibility - 8.0.40 CommunityToolkit.Maui - 9.0.1 CommunityToolkit.Mvvm - 8.2.2
(on .net 7) - Pre upgrade CommunityToolkit.Maui - 5.1.0 CommunityToolkit.Mvvm - 8.2.0
Steps to Reproduce
UI will navigate back to main page however, you'll notice that you'd get an exception.
Link to public reproduction project repository
FileIssue.zip
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
net8.0-windows10.0.19041.0, net7.0-windows10.0.19041.0
Did you find any workaround?
Workaround was to call the sync version of the File.WriteAllText method and return
Task.CompletedTask
. Other methods like usingseem to have worked too, though I haven't thoroughly tested this implementation as it was causing another issue and I found this issue while replacing this existing implementation.
Relevant log output