question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
miloushcommented, Nov 3, 2022

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 use OnLoad 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, where

  • 03 01 Tag 259 (Compression)
  • 04 00 Type 4 (LONG)
  • 01 Count
  • 00 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.

0reactions
singhashish-wpfcommented, Apr 24, 2023

@ZetaKebab Could you please share inputs on the above question?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found