maui
                                
                                 maui copied to clipboard
                                
                                    maui copied to clipboard
                            
                            
                            
                        XmlSerializer Creation throws FileNotFoundException
Description
The unexpected pause does not do any harm in that the missing file seems to be optional and the exception gets caught before it returns to user code, Nonetheless it's mighty confusing and tedious to get around, especially on Android, because even if you disable break on FileNotFoundException the debugger still pauses with a message like this:

Even more annoyingly it seems to break (or pause) twice for each new XmlSerializer created.
There are several things that don't seem right:
- Using an exception to report a normal situation (a missing optional file) is likely to cause confusion and is especially annoying migrating code from Xamarin which does not do this.
- Throwing the exception once per XmlSerializer is bad enough, doing it twice is worse
- In Android disabling that Break applies to all modules (unlike Windows where you can at least ignore exceptions in a named module). This may be a feature of Android.
- When you DO inhibit the break in Android it pauses anyway (with the message above).
If this needs to be split into multiple issues, I can do that, just let me know.
Steps to Reproduce
- Unzip the project from XmlSerializerException.zip
- In visual Studio Exception Settings enable Break on System.IO.FileNotFoundException
- Build and run the project on Android, it should break on the statement
new XmlSerializer(typeof(Person));in MainPage.Xaml.cs
- Press "continue" and it will break again.
- Restart the application
- This time disable Break on System.IO.FileNotFoundException
- Run the project under the debugger again and note that it still pauses on  System.IO.FileNotFoundExceptioneven though Break is disabled for that Exception.
Version with bug
6.0.400 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows
Affected platform versions
Android 11, Windows 10
Did you find any workaround?
Just continue through it and the system will usually keep working.
Relevant log output
No response
@david-maw can you please upload your reproduction to a github repository?
Hi @david-maw. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@PureWeen yes, but it'll be a little effort, is the zipped version not helpful? Should I submit future issues with GitHub repos rather than simply zipping up the sources? If so, that's fine, I can do it, it's just a difference in how I create examples.
@david-maw I've tried run with your repro project, I can see the exception break twice, but when disable the System.IO.FileNotFoundException In visual Studio Exception Settings and restart the project, the System.IO.FileNotFoundException is not throw, see my video, tell me if I miss something.

Hi @david-maw. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@kristinx0211 Interesting, I see the same problem on two different Android versions (one in the emulator one a physical device), I wonder if it is something in my local configuration? I've reloaded VS and the Android SDK so if it is something local it's a bit obscure and of course, your question only addresses item 4, not the first three (which really boil down to "throwing an exception for a non-problem is bad").
Anyway, here's what I see.

@david-maw  do you have break in all exceptions on? https://www.christianfindlay.com/blog/visual-studio-break-on-all-exceptions
Hi @david-maw. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Hi @rmarinho all the CLR Exceptions except System.IO.FileNotFoundException are enabled, it is disabled, but it still breaks, which is just plain weird and perhaps some sort of local problem, interestingly when I turn off all CLR exceptions it no longer breaks.
As the URL you pointed to above says "if all is well, the app shouldn't throw exceptions" and indeed on Windows it doesn't, but it does in Android and that's my underlying complaint. Breaking on a disabled exception seems like it might be a separate issue.
I am having the same problem (on a physical device! No problem on the emulator), however in .NET for Android (not using MAUI). It's pretty annoying to have the debugger break every time, especially because I am doing a lot of XML deserialization in my app and at some point, the debugging session breaks completely. Would appreciate if this could be fixed (probably this is the wrong repo though and the issue has to be moved to the Xamarin.Android repo)
Same issue with a WPF application (.net 6, no MAUI) when accessing Properties.Settings (those Settings derived from System.Configuration.ApplicationSettingsBase)