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:
- Created a year ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
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 aBitmapFrame
or by adding someSuportsMetadata
property on the sources. That said, I don’t think a first chance exception is such a serious problem here.@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.
I was really surprised that it had just this comment also in the code 😞