Create New Presentation with Error: Unable to Cast Object of Type '' to Type 'System.Int32'

Hi Aspose Support Team,

I am currently using Aspose.Slides for .NET version 25.4.0.
When attempting to load a PowerPoint file using a stream, I encounter an exception during the creation of the Presentation object.

Here is the relevant code snippet:

var docBytes = await File.ReadAllBytesAsync(file.FullName, token);
using var docStream = new MemoryStream(docBytes);
var ppt = new Presentation(docStream);

The exception is thrown at the following line:

new Presentation(docStream);

The error message and stack trace are shown below:

Aspose.Slides.PptxReadException: Unable to cast object of type ‘e’ to type ‘System.Int32’.
—> System.InvalidCastException: Unable to cast object of type ‘e’ to type ‘System.Int32’.
at.(IDocumentProperties )
at e.(e , IDocumentProperties, e )
at e.(e , IPresentation)
at e.(Presentation , Stream, InterruptionToken )
— End of inner exception stack trace —
at e.(Presentation , Stream, InterruptionToken )
at Aspose.Slides.Presentation(Stream , Boolean)
at Aspose.Slides.Presentation.(Stream , Boolean)
at Aspose.Slides.Presentation…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Slides.Presentation…ctor(Stream stream)

Due to upload restrictions, I am currently unable to attach the PowerPoint file.
Please advise on an alternative method to provide the file if needed.

@Rachel_Lee

  • Are you trying to create a new blank presentation or loading an existing file when this error occurs?
  • If loading a file, can you confirm the source and format of the file (e.g., .pptx, .ppt, corrupted, password-protected)?
  • Is the stream you’re passing to the Presentation constructor valid, non-null, and positioned at the beginning?
  • Are you using any custom document properties or metadata in the presentation?
  • Can you reproduce this issue with a simple new presentation (e.g., new Presentation() without a stream)?
  • Has this code worked with previous versions of Aspose.Slides or is it a new implementation?

This is not helping

@Rachel_Lee,

Thank you for providing the details and the sample code snippet.

Unfortunately, without the PowerPoint presentation file, we are unable to accurately evaluate your issue and provide effective assistance. Therefore, we kindly request you to compress the sample file into a ZIP format and attach it for our review. If you prefer not to upload the file directly here, you may use a file-sharing service (e.g., Google Drive, Dropbox, or your private service) and share the download link here. Please ensure that no credentials are required to access the file.

Additionally, we recommend trying Aspose.Slides.NET 25.12.0 (Releases | NuGet) to see if the newer version resolves the issue, as it includes various enhancements and fixes.

@Rachel_Lee,

Did you try loading the PowerPoint presentation file directly from the file path instead of using streams?

Presentation presentation = new Presentation(file_path);

Moreover, I have set this thread to “private,” ensuring that only you and authorized Aspose staff can view or download the attachments. No other users will have access. You can now share your attachments securely. However, if you still have concerns, please feel free to replace any confidential data in your Presentation file with dummy data before sharing it with us.

Hi amjad.sahi,

Thank you for your advice. Here is the sample file.
I also followed your suggestion and tried loading the PowerPoint presentation file directly, but the same error still occurs.

測試檔案.pptx.zip (67.8 KB)

@Rachel_Lee,

Thanks for providing us PowerPoint Presentation file.

I tested your scenario/case using the Aspose.Slides for .NET v25.12 and I was able to reproduce the issue/exception you mentioned by using your template PPTX file.:

string directory = "e:\\test2\\測試檔案.pptx";
using FileStream ReportStream = File.Open(directory, FileMode.Open, FileAccess.ReadWrite);
using Aspose.Slides.Presentation ap = new(ReportStream);//exception

We require thorough evaluation of the issue. 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-45249

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.

Thank you for your assistance.
May I ask how I will be notified once this issue is fixed?

By the way, could you please help set this thread to public or protected (so that anyone with the link can access it)?
Other members of our team would like to follow and track this thread as well.
The shared file does not contain any sensitive or confidential information, so making it public is acceptable for us.

@Rachel_Lee,

Yes, once there is an update on the ticket or the issue is resolved, you will be notified here in this thread.

I have made the thread public again. Now everyone should be able to access it.

Thanks for your assistant

@Rachel_Lee,

You are welcome. We will provide you with updates on your logged issue as soon as they become available.