-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
XmlSerializer Creation throws FileNotFoundException #83152
Comments
@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 |
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"). |
@david-maw do you have break in all exceptions on? |
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 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) |
I'm observing this as well on Android and it is extremely annoying. We need to either be able to disable exceptions (disabling Exception and FileNotFoundException in Exception Settings does nothing), or XmlSerializer needs a way to be initialized without throwing all those exceptions. The type it's being given is available inside my assembly. There's no reason XmlSerializer needs to be attempting to load anything else. |
Certainly, the standard practice I'm familiar with is "don't throw exceptions if there's no error" and Microsoft's Framework Design Guidelines say "DO NOT use exceptions for the normal flow of control, if possible" which seems pretty unambiguous. My money's on a simple oversight in the code but since I don't know the code, what looks trivial (check for a file being present before trying to open it) could be complex to change. |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-xml Issue DetailsDescriptionThe 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:
If this needs to be split into multiple issues, I can do that, just let me know. Steps to Reproduce
Version with bug6.0.400 (current) Last version that worked wellUnknown/Other Affected platformsAndroid, Windows Affected platform versionsAndroid 11, Windows 10 Did you find any workaround?Just continue through it and the system will usually keep working. Relevant log outputNo response
|
No idea what changed but with .NET 7 Android seems ok and Windows shows the problem. |
I'm still seeing this with .NET 7 Maui and Android. |
I suspect when this issue does not present itself, it is because XmlSerializer is using a reflection-based implementation under the covers which does not attempt to load a pre-generated serializer assembly. |
What about making XmlSerializer.Mode public to force reflection mode? This would prevent loading the pre-gen assemblies. |
Curiously I still get the FileNotFoundException even when the XmlSerializers.dll files exists when using the serializer generator: |
I'm getting this exception as well upon first request with a WebAPI project. I am using SignalRSwaggerGen for documenting a SignalR Hub with Swagger API doc gen. Here is the exception thrown. There are two exceptions related to this, both mostly the same thrown at two different points in the call stack: System.IO.FileNotFoundException I'm currently trying to figure out how to deal with this. I'd prefer not to use the "Only my code" solution because I'm learning sometimes it is the way my code is interacting with core libs or 3rd party assemblies that causes exceptions and find that to sometimes be valuable indicators that something could be getting misused. |
I have this problem in my IIncrementalGenerator. Optional info: |
@jeremy-visionaid I had the same issue, had to do my own AssemblyResolve handler, as seen in my working example here: I would welcome an alternative solution. |
@stewienj Awesome, thanks for sharing! Fingers crossed for an upstream fix still :) |
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:
If this needs to be split into multiple issues, I can do that, just let me know.
Steps to Reproduce
System.IO.FileNotFoundException
new XmlSerializer(typeof(Person));
in MainPage.Xaml.cs
System.IO.FileNotFoundException
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
The text was updated successfully, but these errors were encountered: