NullReferenceException Occurs When Saving a Presentation as PPTX in C#

Hi,

I have a single slide sample PPTX which I am using in following code:

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.Animation;
using Aspose.Slides.Charts;
using Aspose.Slides.SmartArt;
using Aspose.Slides.Ink;
using System.Drawing;
using System.Drawing.Imaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.Xml;
using System.Threading;
using System.Reflection;
using System.IO;
using System.Drawing.Text;
class Program
{
    static void Main(string[] args)
    {
        try
        {

            // Load the presentation
            using (Presentation presentation = new Presentation("sample.pptx"))
            {
               //Print number of slides
                Console.WriteLine("Number of slides in the presentation: " + presentation.Slides.Count);

                presentation.Save("C:\\output\\sample.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}

Above code results in following error message:
An error occurred: Object reference not set to an instance of an object.

Call Stack:

Aspose.Slides.dll!Aspose.Slides. .(System.Collections.Generic.List<Aspose.Slides. > ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. , Aspose.Slides. , Aspose.Slides. , bool , Aspose.Slides. , bool , ref int , Aspose.Slides.  , ref bool  ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. , Aspose.Slides. , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. . (Aspose.Slides.TextFrame , Aspose.Slides. , Aspose.Slides.IBaseSlide , Aspose.Slides. , Aspose.Slides.​ [] ) Unknown
Aspose.Slides.dll!Aspose.Slides. .vvsthmedpyg3372nznm7qq8padsvbrhg (Aspose.Slides. , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides.​ , float , float , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides.​ , out Aspose.Slides. , out System.Drawing.RectangleF , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides.​ , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. ​.w7fhcez8l9bmn726sezg7t7ctbz3hlnq (Aspose.Slides. , Aspose.Slides. , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .9kpkg4h9kxez6yd973jy2vvmtbaxnntd (Aspose.Slides. , Aspose.Slides.Shape , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. , Aspose.Slides. , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .w7fhcez8l9bmn726sezg7t7ctbz3hlnq (Aspose.Slides. , Aspose.Slides. , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. , Aspose.Slides. , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. , Aspose.Slides.IShapeFrame , Aspose.Slides. , bool , bool , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(System.Drawing.Size , Aspose.Slides. ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(System.Drawing.Size ) Unknown
Aspose.Slides.dll!Aspose.Slides.Slide.GetThumbnail(System.Drawing.Size imageSize) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides. ​ , Aspose.Slides.IPresentation , Aspose.Slides.Export.IPptxOptions ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides.Presentation , Aspose.Slides.UnsupportedProps.PresentationTypeEx , Aspose.Slides.Export.IPptxOptions , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides. .(Aspose.Slides.Presentation , System.IO.Stream , Aspose.Slides.UnsupportedProps.PresentationTypeEx , Aspose.Slides.Export.IPptxOptions , Aspose.Slides.InterruptionToken ) Unknown
Aspose.Slides.dll!Aspose.Slides.Presentation.(System.IO.Stream , Aspose.Slides.UnsupportedProps.PresentationTypeEx , Aspose.Slides.Export.IPptxOptions ) Unknown
Aspose.Slides.dll!Aspose.Slides.Presentation.Save(System.IO.Stream stream, Aspose.Slides.Export.SaveFormat format, Aspose.Slides.Export.ISaveOptions options) Unknown
Aspose.Slides.dll!Aspose.Slides.Presentation.Save(string fname, Aspose.Slides.Export.SaveFormat format) Unknown

Can you pls let us know what is the reason for this exception and how can we rectify it ?

Thanks,
@bhav
sample.zip (81.8 KB)

Internal Ref: CONN-4167151

@bhav

It looks like you’re encountering a NullReferenceException when trying to save your presentation. This error typically occurs when you’re trying to access an object that hasn’t been initialized.

Here are a few steps to help you troubleshoot and resolve the issue:

  1. Check the Presentation File: Ensure that the “sample.pptx” file exists at the specified path and is not corrupted. You can try opening it manually in PowerPoint to verify.

  2. Verify Output Directory: Make sure that the output directory “C:\output\” exists. If it doesn’t, create it before running your code.

  3. Update Aspose.Slides: Ensure that you are using the latest version of the Aspose.Slides library. Sometimes, bugs are fixed in newer releases.

  4. Debugging: Add additional logging to check if the presentation object is being created successfully. For example, after loading the presentation, you can log the number of slides:

    Console.WriteLine("Number of slides: " + presentation.Slides.Count);
    
  5. Try a Different File: If possible, test with another PPTX file to see if the issue is specific to the “sample.pptx” file.

Here’s a modified version of your code with additional checks:

using Aspose.Slides;
using Aspose.Slides.Export;
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        try
        {
            string inputFilePath = "sample.pptx";
            string outputFilePath = "C:\\output\\sample.pptx";

            // Check if the input file exists
            if (!File.Exists(inputFilePath))
            {
                Console.WriteLine("Input file does not exist.");
                return;
            }

            // Load the presentation
            using (Presentation presentation = new Presentation(inputFilePath))
            {
                // Print number of slides
                Console.WriteLine("Number of slides in the presentation: " + presentation.Slides.Count);

                // Save the presentation
                presentation.Save(outputFilePath, SaveFormat.Pptx);
                Console.WriteLine("Presentation saved successfully.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}

Please run this updated code and check if it resolves the issue. If the problem persists, provide any error messages or additional details, and I will assist you further. Thank you!

The problem seems to be with this line:
Multiple Linear Regression: 𝑬(𝒀│𝑿)= 𝜶+ 𝜷𝟏𝑿1 + 𝜷𝟐𝑿𝟐 + 𝜷𝟑𝑿𝟑 + ….

@bhav,
Thank you for reporting the issue. I have reproduced the error you described. We apologize for any inconvenience caused.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-45083

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

We need some time to investigate the case. We will keep you updated.

The issues you found earlier (filed as SLIDESNET-45083) have been resolved in Aspose.Slides for .NET 25.9 (ZIP, MSI, NuGet, Cross-platform).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.