InvalidOperationException: Failed to write to the stream. (Exception from HRESULT: 0x88982F71) <p>While attempting to write a FixedSocument to Xps file, I get the following exception:</p> <pre><code>System.InvalidOperationException was unhandled HResult=-2146233079 Message=Cannot write to the stream. Source=PresentationCore StackTrace: at System.Windows.Media.Imaging.BitmapEncoder.SaveFrame(SafeMILHandle frameEncodeHandle, SafeMILHandle encoderOptions, BitmapFrame frame) at System.Windows.Media.Imaging.BitmapEncoder.Save(Stream stream) at System.Windows.Xps.Serialization.ImageSourceTypeConverter.ReEncodeImage(BitmapSource bitmapSource, BitmapEncoder encoder, Stream stream) at System.Windows.Xps.Serialization.ImageSourceTypeConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType) at System.Windows.Xps.Serialization.VisualSerializer.WriteBitmap(String attribute, ImageSource imageSource) at System.Windows.Xps.Serialization.VisualSerializer.BrushToString(Brush brush, Rect bounds) at System.Windows.Xps.Serialization.VisualSerializer.FindBrush(Brush brush, Rect bounds) at System.Windows.Xps.Serialization.VisualSerializer.WriteBrush(String attribute, Brush brush, Rect bounds) at System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawGeometry(Brush brush, Pen pen, Geometry geometry) at System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawImage(ImageSource image, Rect rectangle) at System.Windows.Xps.Serialization.DrawingContextFlattener.DrawImage(ImageSource image, Rect rectangle) at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform) at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform) at System.Windows.Xps.Serialization.VisualTreeFlattener.StartVisual(Visual visual) at System.Windows.Xps.Serialization.ReachVisualSerializer.SerializeTree(Visual visual, XmlWriter resWriter, XmlWriter bodyWriter) at System.Windows.Xps.Serialization.ReachVisualSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.ReachUIElementCollectionSerializer.SerializeUIElement(Object uiElement) at System.Windows.Xps.Serialization.ReachUIElementCollectionSerializer.SerializeUIElements(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachUIElementCollectionSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(SerializablePropertyContext serializedProperty) at System.Windows.Xps.Serialization.ReachSerializer.SerializeProperty(SerializablePropertyContext serializablePropertyContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeProperties(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObjectCore(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.FixedPageSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.FixedPageSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.ReachPageContentSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.ReachPageContentCollectionSerializer.SerializePageContent(Object pageContent) at System.Windows.Xps.Serialization.ReachPageContentCollectionSerializer.SerializePageContents(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachPageContentCollectionSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(SerializablePropertyContext serializedProperty) at System.Windows.Xps.Serialization.ReachSerializer.SerializeProperty(SerializablePropertyContext serializablePropertyContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeProperties(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObjectCore(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.FixedDocumentSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext) at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.FixedDocumentSerializer.SerializeObject(Object serializedObject) at System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(Object serializedObject) at System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(Object serializedObject, Boolean isSync) at System.Windows.Xps.XpsDocumentWriter.Write(FixedDocument fixedDocument) [...] InnerException: ErrorCode=-2003292303 HResult=-2003292303 Message=Failed to write to the stream. (Exception from HRESULT: 0x88982F71) InnerException: </code></pre> <p>The FixedDocument contains only one page with a couple of images.</p> <p>Any suggestion about how to solve the problem?</p> <p>thanks!</p>