-
Notifications
You must be signed in to change notification settings - Fork 1k
Introduce InvalidImageFormatException in .NET #13430
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
Labels
area-System.Drawing
System.Drawing issues
untriaged
The team needs to look at this issue in the next triage
Comments
|
Tagging subscribers to this area: @dotnet/area-system-drawing |
Fair enough. I'm just a C# rookie. I still think something should be done, though. The Exception is not correct and could lead to confusion (as it did in my case). |
Awesome! 👍
…On Thursday, May 8th, 2025 at 20:48, Jeremy Kuhne ***@***.***> wrote:
JeremyKuhne left a comment [(dotnet/winforms#13430)](#13430 (comment))
***@***.***(https://github.com/Wazi2025) unfortunately GDI+ tells us that it is out of memory, and as such we don't have any context. That said, I plan to change the exception to something else as it is almost never a low memory situation. [#12627](#12627) covers this, feel free to add additional feedback there.
—
Reply to this email directly, [view it on GitHub](#13430 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/BPUBHXRON4JUW27BBVLXE4L25ORGXAVCNFSM6AAAAAB4XGXST2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQNRTHE3TKOJQGU).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-System.Drawing
System.Drawing issues
untriaged
The team needs to look at this issue in the next triage
Description
When attempting to load a non-image file (e.g., a PDF) using Image.FromFile(), .NET throws an OutOfMemoryException. This is misleading, as the error isn't due to memory exhaustion but rather an invalid file format.
Proposed Solution:
Introduce a new exception type, InvalidImageFormatException, to be thrown when Image.FromFile() encounters a file that isn't a valid image. This would provide clearer, more accurate error handling for developers.
Benefits:
Improved Clarity: Developers can more easily identify and handle errors related to invalid image formats.
Enhanced Debugging: Reduces confusion during debugging by providing a specific exception for this scenario.
Better Practices: Encourages more precise exception handling and promotes best practices in error management.
Reproduction Steps
using var image = Image.FromFile(filePath);
If the file in question is not an image file it throws an : 'System.OutOfMemoryException' in System.Private.Windows.Core.dll
Expected behavior
It should throw a new type of Exception instead of OutOfMemoryException.
Actual behavior
Exception thrown: 'System.OutOfMemoryException' in System.Private.Windows.Core.dll
Regression?
Not sure. I only started with C# in February this year.
Known Workarounds
No response
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: