ArgumentException: Parameter is not valid on loading presentation (C# .NET)

Greetings all,

We are using .Net version of aspose to extract image and content from a big slide deck (88 slides with graphics). We also use OpenXML for other stuff like extracting individual pptx file from a deck of slides. On 40th or so slide (it appears to be at random places within the deck), suddenly aspose throws the following (below) exception. In notepad, what's between the empty spaces below are funny/non-readable chars. If we catch the exception and continue the loop, aspose has no issues extracting subsequent slides. OpenXML has no issues processing any of the slides.

We thought it maybe an issue with one particular slide. However, extracting that one slide and feeding through aspose didn't cause an issue. At this point,we don't have any evidence that one slide is causing this issue. The stack trace appears internal to Aspose. Can someone think of a reason that we are getting this stack trace? Thanks in advance.



System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at Aspose.Slides.ImageCollection.AddImage(MemoryStream stream)
at .( )
at .( , IPresentation )
at .(Presentation , Stream )
at Aspose.Slides.Presentation.(Stream )
at Aspose.Slides.Presentation.(Stream )
at Aspose.Slides.Presentation..ctor(String file, LoadOptions loadOptions)

Hi,


I have observed the issue shared by you and request you to please try using Aspose.Slides for .NET 15.5.0 on your end first. If there is still an issue then please provide the working sample project and source presentation reproducing the issue on your end. I will investigate the issue further on my end to help you out.

Many Thanks,

Thank for you help on this. We were using Aspose Slide 15.4.0.0 and I downloaded 15.5.0.0 from your website. Sadly, we are stilling getting the same error (below). The code for extraction of the content that throws the error is also pasted below. We also use Aspose for extracting images from pptx file. That process also throws the same exact exception.


The pptx file in question is 40MB. Do you guys have a dropbox/ftp of some sort so I can send to you?

Thanks again for your help!



7/6/2015 9:58:13 PM:Caught exception in extractAllImagesFromPPTXSlides System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at Aspose.Slides.ImageCollection.AddImage(MemoryStream stream)
at .( )
at .( )
at .( , IPresentation )
at .(Presentation , Stream )
at Aspose.Slides.Presentation.(Stream )
at Aspose.Slides.Presentation.(Stream )
at Aspose.Slides.Presentation…ctor(String file, LoadOptions loadOptions)
at PPTXProjectExtractorSrvs.ExtractorProc.extractAllImagesFromPPTXSlidesAspose() in c:\MasterSolution\PPTXProjectExtractorSrvs\ExtractorProc.cs:line 998


Content extractor
public void extractSlideContentAspose()
{
try
{

// EventLog.WriteEntry(evntSource, "Method: GetSlideContent - doc doesn’t exists. path " + pathToPPTXFile, EventLogEntryType.Error);
LogIt(“Method ASPOSE ExtractSlieContent, About to extract content”);

string[] files = System.IO.Directory.GetFiles(pathToPPTXDirectory + “slides\”, “*.pptx”).OrderBy(d => new FileInfo(d).CreationTime).ToArray();
LogIt(“Method ASPOSE Slide text extraction Number of pptx files:” + files.Length);
if (files.Length < 1)
return;
Aspose.Slides.License lic = new Aspose.Slides.License();
lic.SetLicense(“Aspose.Slides.lic”);

for (int ini = 0; ini < files.Length; ini++)
{
string pathfiles = files[ini];
StringBuilder sb = new StringBuilder();
LogIt(“ASPOSE METHOD extracting text. Now doing:” + pathfiles);
//Instatiate Presentation class that represents a PPTX file
Aspose.Slides.Presentation pptxPresentation = new Aspose.Slides.Presentation(pathfiles);

//Get an Array of ITextFrame objects from all slides in the PPTX
Aspose.Slides.ITextFrame[] textFramesPPTX = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(pptxPresentation, true);

//Loop through the Array of TextFrames
for (int i = 0; i < textFramesPPTX.Length; i++)
{

//Loop through paragraphs in current ITextFrame
foreach (Aspose.Slides.IParagraph para in textFramesPPTX[i].Paragraphs)
{
//Loop through portions in the current IParagraph
foreach (Aspose.Slides.IPortion port in para.Portions)
{
//Display text in the current portion
// Console.WriteLine(port.Text);
// System.IO.File.AppendAllText(pathToPPTXDirectory + “content\” + ini.ToString() + “.txt”,port.Text);

}
sb.Append(para.Text);
sb.Append(Environment.NewLine);

}
}
System.IO.File.AppendAllText(pathToPPTXDirectory + “content\” + ini.ToString() + “.txt”, sb.ToString());
} //foreac
LogIt(“ASPOSE text extraction DONE”);
}
catch (Exception ex)
{
LogIt("ASPOSE Caught exception at ExtractSlideContent " + ex.ToString());

}


}







Hi,


I have observed the sample code shared and request you to please share the presentation file with us. You can share the file in your dropbox or other FTP server and share the download link with us. I will get the presentation and investigate the issue on my end.

Many Thanks,

Thank you for your help and response. Please find the pptx in question at the link below:

http://54.164.20.162/sample.pptx

Thanks again

Hi,

Thank you for sharing the sample presentation with us. I have worked with the presentation file shared and have tested that using sample code shared by you and Aspose.Slides for .NET 15.5.0. I have not been able to reproduce the issue on my end in several iterations and there is no exception thrown. For your kind reference, I have also attached the generated output as well.

Many Thanks,

Thanks for trying. However, we (a paying customer) are getting Aspose internal exceptions. As you saw, the code was copied from your website so we are not doing anything out of the ordinary other than wrapping it in a try/catch statement.


Since we don’t have access to Aspose source code to know at what point the exception is thrown, can you shine some light as to what causes such exception? Is it a resource issue? Is it a file handle issue? Aspose can’t find a file or something? Again, since this is an INTERNAL Aspose exception, unless and until you guys tell us the cause, we have no course of action.

Is there anything that we should do or not do in order to prevent this error?

Thanks for all your help.

Hi,

I like to share that both I and our product team has used the attached sample code with your presentation and issue is not reproduced on our end. We are unable to share the reason of the issue unless we are able to reproduce that on our end. Please share the complete working sample visual studio project with which you are able to reproduce the issue. Please also share the environment details on your end as well along with .NET version. I have tested in Windows 7 x64 with 8 GB Ram and Visual Studio 2010.

Many Thanks,

Thank you for your help on this. I’ll be more than glad to share the project with you. I don’t want to post it online. Is there an email address that I can send the zip file?

Thanks so much again.

Hi,

You can please share the sample project with us by following these guidelines. Please notify us here once you have shared the project. Please also share all the requested information with us as well that I have made in my previous post.

Many Thanks,


Hello,

I just sent you a private message as to where you can get the project files and pptx file. Please let me know if you need anything else.

Thanks again for all the help on this.

Hi,

I have received the sample project from you and have observed that you are creating the Windows Service in your application. Can you please share the steps that I may use on my end to use the sample project and reproduce the issue. I have installed the service and started that. I have attached the image of log when services is started.

Many Thanks,

Hi, Aspose. I faced the same issue while i was trying to crop shape’s thumbnail to get shape’s position. As i need also to get portion position regular aspose methods like GetRectangle() doesn’t fit. I added sample project with a sample file to this message.

@obrusentsov,

I have tried observing your requirements and have not been able to completely understand them. Can you please elaborate them in the form of source files, generated file and desired output file. Moreover, I suggest you to please try using Aspose.Slides for .NET 19.4 on your end first as well.

I am unable to find any project attached with your message as well.

Hi Mudassir, sorry for the delay. I just created another sample project and added it to my dropbox so you could download it. In this sample project you can find the source file and the solution file with this issue reproducible. https://www.dropbox.com/s/pfqj5vd4tpnj80x/ParameterIsNotValid.zip?dl=0

@obrusentsov,

I have worked with sample project shared by you and tried using that on my end. The exception that you have shared is thrown on line 152. Actually, your code is saving file with extension .emf in the end. Whereas on following line you are trying to access a .PNG file.

using (var bitmap = new Bitmap(Path.GetFullPath(shape)))

I suggest you to please try using following code on your end.

using (var bitmap = new Bitmap(Path.GetFullPath(shape+ext)))

Please also check the following images for your kind reference as well.