We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Presentation.Save Method Throws NullReferenceException after Slide Cloning

When running our unit test suite, we get the following error on every second run

 NullReferenceException	Object reference not set to an instance of an object.	   
    at \x05  ​.get_KeepTextFlat()
    at Aspose.Slides.TextFrameFormat.get_KeepTextFlat()
    at \x06 ​ .\x02(ITextFrame \x02, \x06    \x03, \x08 ​  \x05)
   at \x06 ​ .\x02(ITextFrame \x02, \x02 \x03, \x08 ​  \x05)
   at \x0f   .\x02(IAutoShape \x02, \x03    \x03, \x05 ​  \x05, \x0f​   \x08)
   at \x02   .\x02(IShape \x02, \x06    \x03, \x05 ​  \x05, \x0f​   \x08)
   at \x02   .\x02(IGroupShape \x02, \x06    \x03, \x05 ​  \x05, \x0f​   \x08)
   at \x08   .\x02(IBaseSlide \x02, \x0f ​  \x03, \x05 ​  \x05)
   at \x05​  .\x02(ILayoutSlide \x02, \x0e​   \x03, \x05 ​  \x05)
   at \x08 ​ .\x02(ILayoutSlide \x02)
   at \x06 ​ .\x02(\x0e    \x02, ILayoutSlide \x03, \x05 ​  \x05, \x08 ​  \x08)
   at \x06 ​ .\x02(\x0e    \x02, IMasterSlide \x03, Boolean \x05, \x08 ​  \x08)
   at \x06 ​ .\x02(IPresentation \x02, Stream \x03, PresentationTypeEx \x05, IPptxOptions \x08, InterruptionToken \x06)
   at Aspose.Slides.Presentation.\x02(Stream \x02, PresentationTypeEx \x03, IPptxOptions \x05)
   at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format, ISaveOptions options)
   at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format)
   at [Calling code...]

The following is a simplified version of what we are doing. We are basically splitting a presentation into separate presentations for each slide.

public void Save(ISlide original)
{
    using var slidePres = new Presentation(new LoadOptions
        {
            BlobManagementOptions = new BlobManagementOptions
                {
                    IsTemporaryFilesAllowed = false
                }
        });
        slidePres.Slides.First().Remove();
        slidePres.SlideSize.SetSize(960, 540, SlideSizeScaleType.EnsureFit);

        slidePres.Slides.AddClone(original);

        using var contentStream = File.OpenWrite("SomePath.pptx");
        slidePres.Save(contentStream, SaveFormat.Pptx);
}

This is the original presentation that we are using in the tests

SingleSlide.7z (24.0 KB)

@SlideForce,
Welcome to our community! Thank you for contacting support.

With Aspose.Slides 21.10, I loaded your presentation file and passed the first slide to your Save method. There were no exceptions in my test. Please check your results using the latest version of Aspose.Slides.

Thanks for the reply.
I am also using 21.10.
The error does not happen every time, however, we have multiple tests running concurrently that call the method above.
Could the error be caused by some kind of thread unsafety in Aspose?
With the IsTemporaryFilesAllowed = false I would think that Aspose does not touch the disk at all, is that correct (the ISlide original also comes from a presentation that is created directly in memory with IsTemporaryFilesAllowed = false set).

Since the exception is a NullReferenceException I would think that this is some kind of bug in Aspose that some things have somehow not been initialized, but I cannot debug anything due to your obfuscated code, but maybe you can give a hint as to what might be causing the issue? Are we doing something wrong copying slides from one presentation to another in a multithreaded context?

Sincerely,
Alexander

@SlideForce,
Unfortunately, using a single presentation instance across multiple threads is unsafe. You should check this first.

Documents: Multithreading in Aspose.Slides