maui icon indicating copy to clipboard operation
maui copied to clipboard

XmlSerializer Creation throws FileNotFoundException

Open david-maw opened this issue 3 years ago • 10 comments

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:

nobreakdialog

Even more annoyingly it seems to break (or pause) twice for each new XmlSerializer created.

There are several things that don't seem right:

  1. 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.
  2. Throwing the exception once per XmlSerializer is bad enough, doing it twice is worse
  3. 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.
  4. 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

  1. Unzip the project from XmlSerializerException.zip
  2. In visual Studio Exception Settings enable Break on System.IO.FileNotFoundException
  3. Build and run the project on Android, it should break on the statement new XmlSerializer(typeof(Person)); in MainPage.Xaml.cs
  4. Press "continue" and it will break again.
  5. Restart the application
  6. This time disable Break on System.IO.FileNotFoundException
  7. Run the project under the debugger again and note that it still pauses on System.IO.FileNotFoundException even 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 avatar Jun 24 '22 23:06 david-maw

@david-maw can you please upload your reproduction to a github repository?

PureWeen avatar Jun 25 '22 15:06 PureWeen

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.

msftbot[bot] avatar Jun 25 '22 15:06 msftbot[bot]

@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 avatar Jun 26 '22 05:06 david-maw

@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. 8322

kristinx0211 avatar Jun 27 '22 10:06 kristinx0211

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.

msftbot[bot] avatar Jun 27 '22 10:06 msftbot[bot]

@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. XmlSerializerException

david-maw avatar Jun 27 '22 15:06 david-maw

@david-maw do you have break in all exceptions on? https://www.christianfindlay.com/blog/visual-studio-break-on-all-exceptions

rmarinho avatar Jul 21 '22 14:07 rmarinho

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.

msftbot[bot] avatar Jul 21 '22 14:07 msftbot[bot]

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.

david-maw avatar Jul 21 '22 15:07 david-maw

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)

tipa avatar Aug 10 '22 13:08 tipa

Same issue with a WPF application (.net 6, no MAUI) when accessing Properties.Settings (those Settings derived from System.Configuration.ApplicationSettingsBase)

AndreasHaackEpi avatar Oct 04 '22 12:10 AndreasHaackEpi