Ticket T1279717
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

RichEditControl - NullReferenceException occurs when an SVG image is inserted

RichEditControl: Null Reference Exception when trying to insert an SVG image.

created 2 days ago

System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream throws a Null Reference Exception trying to close a null BitmapStream when called from XpfPainter.CreatePlatformImageSourceCore.

C#
static ImageSource CreatePlatformImageSourceCore(OfficeImage img) { BitmapImage imageSource = new BitmapImage(); imageSource.BeginInit(); byte[] bytes = img.GetImageBytesSafe(img.RawFormat); imageSource.StreamSource = new System.IO.MemoryStream(bytes); if (img.SizeInPixels.Width > maxImageSize || img.SizeInPixels.Height > maxImageSize) { double aspectRatio = img.SizeInPixels.Width / img.SizeInPixels.Height; int width, height; if (img.SizeInPixels.Width > maxImageSize) { width = maxImageSize; height = (int)Math.Round(width / aspectRatio); } else { height = maxImageSize; width = (int)Math.Round(height * aspectRatio); } imageSource.DecodePixelWidth = width; imageSource.DecodePixelHeight = height; } //Null Reference Exception Here imageSource.EndInit(); imageSource.Freeze(); return imageSource; }

Answers approved by DevExpress Support

created 2 days ago

Hello Daniel,

We have the following report related to a similar issue: RichEditControl - System.ArgumentException occurs on scrolling a document. Our developers are investigating the issue. Please watch for our updates there.

In the meantime, would you please describe steps to reproduce the issue or share a small sample project where the issue is reproducible? This way, we can ensure that the RichEditControl - System.ArgumentException occurs on scrolling a document issue reported earlier is the same.

    Comments (2)

      Simply inserting any SVG file by going to Insert - Picture seems to cause the issue.
      I have shared a sample project which demonstrates the issue.

      Sasha (DevExpress Support) 20 hours ago

        Hello Daniel,

        Thank you for the clarification and the sample project. It appears that this issue is different. As such, I created a separate report and forwarded it to our developers: RichEditControl - NullReferenceException occurs when an SVG image is inserted. We will update it as soon as we have any results.

        As a workaround, you can render an SVG image as a bitmap and add it to RichEditControl as follows:

        C#
        Document document = richEditControl1.Document; SvgImage svgImage = SvgImage.FromFile("folder.svg"); SvgBitmap svgBitmap = SvgBitmap.Create(svgImage); var bitmap = svgBitmap.Render(null, 1.0); DocumentImage picture = document.Images.Insert(document.Range.Start, DocumentImageSource.FromGdiImage(bitmap));

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.