BitmapFrame: System.IO.FileFormatException: 'Unexpected property type or value.'
See original GitHub issue- .NET Core Version: 6.0
- Windows version: Windows 10 21H2
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
When creating a BitmapFrame from a MemoryStream, it throws a FileFormatException, on specific images:
BitmapFrame Frame = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
Please note that when loading the same faulty image as a Resource and putting it into an Image in XAML, it does not has any issues.
Actual behavior: It gives the following exception:
System.IO.FileFormatException: 'Unexpected property type or value.'
COMException: The bitmap property type is unexpected. (0x88982F8E)
Expected behavior: I expect it not to throw an exception, and load correctly.
Minimal repro:
Please see this sample app I created: https://github.com/ZetaKebab/BitmapFrameIssue
The issue only happens with one of the two images (cover1.jpg
is faulty, not cover2.jpg
).
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Unexpected property type or value on using ...
Throws an error "Unexpected property type or value." using (Stream stream = new FileStream(path, FileMode.Open,FileAccess.Read,FileShare.
Read more >Exceptions thrown by BitmapImage and BitmapFrame
An ArgumentException generally seems to be caused by a corrupted image header or metadata. Scott Hanselman suggests using BitmapCreateOptions.
Read more >WpfPayload.cs - Reference Source - Microsoft
Description: Helper class for creating and accessing WPF Payloads in packages // This file contains the definition and implementation // for the WpfPayload ......
Read more >Class Button
The space between icon and text. The value is applied when there exist icon and text both. The width value is used when...
Read more >New WAD Editor 1.0 [Archive]
Just hold the mouse over buttons to see tips. The most important feature is the possibility to export and import MQO files with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The image metadata is corrupted/invalid. It throws because you are requesting to load the metadata using
BitmapCacheOption.OnLoad
. Using the image as an resource does not useOnLoad
and therefore does not try to touch the metadata.My suspicion about the image having a thumbnail was correct. The thumbnail is compressed and therefore the metadata must contain the Compression EXIF tag. The specification defines the tag as of type SHORT. However, the file contains the tag as of type LONG.
The tag is at offset 158 in the file:
03 01 04 00 01 00 00 00 06
, where03 01
Tag 259 (Compression)04 00
Type 4 (LONG)01
Count00 00 00 06
Value 6 indicating JPEG compressed thumbnail.The exception message is actually accurate. As per the comment in the file, the image was created by gd-jpeg v1.0 (using IJG JPEG v62), which is where the fix needs to be done.
@ZetaKebab Could you please share inputs on the above question?