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.

XpsDocumentWriter.SaveAsXaml - BitmapMetadata is not available on BitmapImage

See original GitHub issue
  • .NET Core Version: 6.0 (guess all versions)
  • Visual Studio 2019, 2022, 2022 preview

Problem description: Attaching WinDbg Preview to a process I see lots of System.NotSupportedException happening with message “BitmapMetadata is not available on BitmapImage”

Why throw instead of checking if metadata is supported or not ?

Actual behavior:

(50e8.3f8): CLR exception - code e0434352 (first chance) Exception object: 000001f93a3e2b20 Exception type: System.NotSupportedException Message: BitmapMetadata is not available on BitmapImage. InnerException: <none> StackTrace (generated): <none> StackTraceString: <none> HResult: 80131515 OS Thread Id: 0x3f8 (19) Child SP IP Call Site 000000ED8423BC68 00007ff8a4b44f69 [HelperMethodFrame: 000000ed8423bc68] 000000ED8423BD60 00007ff831597011 System.Windows.Media.Imaging.BitmapImage.get_Metadata() 000000ED8423BDA0 00007ff82e52057c System.Windows.Media.Imaging.BitmapFrame.Create(System.Windows.Media.Imaging.BitmapSource) 000000ED8423BDF0 00007ff82e520442 System.Windows.Xps.Serialization.ImageSourceTypeConverter.ReEncodeImage(System.Windows.Media.Imaging.BitmapSource, System.Windows.Media.Imaging.BitmapEncoder, System.IO.Stream) 000000ED8423BEB0 00007ff82e517e98 System.Windows.Xps.Serialization.ImageSourceTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext, System.Globalization.CultureInfo, System.Object, System.Type) 000000ED8423BF50 00007ff82e517744 System.Windows.Xps.Serialization.VisualSerializer.WriteBitmap(System.String, System.Windows.Media.ImageSource) 000000ED8423C040 00007ff82e515dab System.Windows.Xps.Serialization.VisualSerializer.BrushToString(System.Windows.Media.Brush, System.Windows.Rect) 000000ED8423C560 00007ff82e514da4 System.Windows.Xps.Serialization.VisualSerializer.FindBrush(System.Windows.Media.Brush, System.Windows.Rect) 000000ED8423C5E0 00007ff82df723bc System.Windows.Xps.Serialization.VisualSerializer.WriteBrush(System.String, System.Windows.Media.Brush, System.Windows.Rect) 000000ED8423C640 00007ff82df70e78 System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawGeometry(System.Windows.Media.Brush, System.Windows.Media.Pen, System.Windows.Media.Geometry) 000000ED8423C810 00007ff82e513f55 System.Windows.Xps.Serialization.DrawingContextFlattener.DrawImage(System.Windows.Media.ImageSource, System.Windows.Rect) 000000ED8423C8A0 00007ff82df6b4ef System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing, System.Windows.Media.Matrix) 000000ED8423CB80 00007ff82df6b7e8 System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing, System.Windows.Media.Matrix) 000000ED8423CE60 00007ff82df6b7e8 System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing, System.Windows.Media.Matrix) 000000ED8423D140 00007ff82df6b7e8 System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing, System.Windows.Media.Matrix) 000000ED8423D420 00007ff82e46fa7b System.Windows.Xps.Serialization.VisualTreeFlattener.StartVisual(System.Windows.Media.Visual) 000000ED8423D930 00007ff82e4f3da0 System.Windows.Xps.Serialization.ReachVisualSerializer.SerializeTree(System.Windows.Media.Visual, System.Xml.XmlWriter, System.Xml.XmlWriter) 000000ED8423D9E0 00007ff82e4f377a System.Windows.Xps.Serialization.ReachUIElementCollectionSerializer.SerializeUIElements(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DA30 00007ff82e4eb27b System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(System.Windows.Xps.Serialization.SerializablePropertyContext) 000000ED8423DA70 00007ff82e4eb1a3 System.Windows.Xps.Serialization.ReachSerializer.SerializeProperties(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DAB0 00007ff82e4f104e System.Windows.Xps.Serialization.FixedPageSerializer.PersistObjectData(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DB90 00007ff82e4bf022 System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(System.Object) 000000ED8423DBD0 00007ff82e4bf022 System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(System.Object) 000000ED8423DC10 00007ff82e4efdb5 System.Windows.Xps.Serialization.ReachPageContentCollectionSerializer.SerializePageContent(System.Object) 000000ED8423DC60 00007ff82e53b75a System.Windows.Xps.Serialization.ReachPageContentCollectionSerializer.SerializePageContents(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DCB0 00007ff82e4eb27b System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(System.Windows.Xps.Serialization.SerializablePropertyContext) 000000ED8423DCF0 00007ff82e4eb1a3 System.Windows.Xps.Serialization.ReachSerializer.SerializeProperties(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DD30 00007ff82e53ae35 System.Windows.Xps.Serialization.FixedDocumentSerializer.PersistObjectData(System.Windows.Xps.Serialization.SerializableObjectContext) 000000ED8423DD80 00007ff82e4bf022 System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(System.Object) 000000ED8423DDC0 00007ff82e539ab4 System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(System.Object) 000000ED8423DE20 00007ff82e5397ef System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(System.Object, Boolean)

Expected behavior:

Looks like this is by design: https://stackoverflow.com/a/17027474/187650 Though, would be much nicer to see if metadata is supported instead of throwing…

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
miloushcommented, Apr 16, 2022

There is a difference between “this source does not support metadata” and “this source supports metadata but does not have any”. If the suggested fix is to always return null, this distinction would be lost.

A better “fix” might be for the XpsDocumentWriter to not ask for metadata, either by first checking whether the source is a BitmapFrame or by adding some SuportsMetadata property on the sources. That said, I don’t think a first chance exception is such a serious problem here.

1reaction
wstaelenscommented, Apr 11, 2022

@lindexi i mean that it should not throw an exception, as the comments in the code also clearly state that it should be better to pass null, which would make the process also much faster/better I believe.

 //do not throw not support exception
 //just pass null

I was really surprised that it had just this comment also in the code 😞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception on BitmapFrame.Create (bug in WPF framework?)
NotSupportedException' occurred in `PresentationCore.dll` Additional information: BitmapMetadata is not available on BitmapImage.
Read more >
BitmapImage.Metadata Property (System.Windows.Media. ...
BitmapImage does not support the Metadata property and will throw a NotSupportedException. public: virtual property System::Windows::Media::ImageMetadata ...
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