ArgumentException when trying to use `SaveAsImageAsync`

I have the attached code to open a PowerPoint presentation and render them as Image. However whenever I call SaveAsImageAsync, the exception is thrown (Exception details below).

    public sealed partial class Presentation : Page
    {
        private IPresentation openingPresentation;

        public Presentation()
        {
            this.InitializeComponent();
        }

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var openingFile = e.Parameter as StorageFile;
            this.openingPresentation = await Syncfusion.Presentation.Presentation.OpenAsync(openingFile);

            await this.LoadPage(0);
        }

        public async Task LoadPage(int number)
        {
            if (number < 0)
            {
                number = 0;
            }

            var totalSlides = this.openingPresentation.Slides.Count;
            if (number >= totalSlides)
            {
                number = totalSlides - 1;
            }

            if (number == -1)
            {
                this.txtPage.Text = "Page 0/0";
                return;
            }

            using (var memoryStream = new MemoryStream())
            {
                await this.openingPresentation.Slides[number].SaveAsImageAsync(memoryStream);

                var bitmapImage = new BitmapImage();

                using (var stream = new InMemoryRandomAccessStream())
                {
                    await stream.WriteAsync(memoryStream.ToArray().AsBuffer());
                    stream.Seek(0);
                    await bitmapImage.SetSourceAsync(stream);
                }

                this.imgSlide.Source = bitmapImage;
            }

            this.txtPage.Text = $"Page {number + 1}/{totalSlides}";
        }

    }

Here are my installed Nuget Packages:



This happens to all PowerPoint files, even empty files. I am fine with no Chart render. The same exception happens when I use it for StorageFile too.

The Exception and Stack Trace:
System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Syncfusion.Presentation.XAMLRenderer.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Syncfusion.Presentation.XAMLRenderer.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Syncfusion.Presentation.SlideImplementation.Slide.d__67.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Syncfusion.Presentation.SlideImplementation.Slide.d__67.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Syncfusion.Presentation.SlideImplementation.Slide.d__64.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at DocumentViewer.Pages.Presentation.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at DocumentViewer.Pages.Presentation.d__2.MoveNext()

P.s: I don't see any button on Forum Editor to mark text as code...

1 Reply

MN Meikanda Nayanar Syncfusion Team May 10, 2018 10:06 AM UTC

Hi Dat Vo, 
Please find the below online documentation link to convert a PowerPoint slide to image in UWP. 
Also, we have created a sample to view PowerPoint slides in UWP environments and attached the sample in below link. 
Please let us know if you need any further assistance in this. 
Thanks, 
Meikandan 


Loader.
Up arrow icon