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

Free Support Forum - aspose.com

Invalid Operation Error while Cloning Slides

Getting this error while trying to add clone slide :

Presentation master= new Presentation(this.getClass().getClassLoader().getResourceAsStream("src/main/resources/slide.pptx"));

Presentation presentation = new Presentation(); 

I am passing the master slide to several methods and executing those methods in parallel. I don’t get any issue when executing them sequentially.
com.aspose.slides.exceptions.InvalidOperationException: Trying to add new cached value with the same keys.


There is issue in your used code. You are cloning the master slide in normal slide with is not right. You need to use the correct slide type for cloning is respecting collection.

Thanks. I was able to figure out the issue.


It’s good to know things are working fine on your end as per suggestion.

Hi, what is the solution to this issue? I am getting the same error. What do you mean by normal slide?

Presentation sourcePPT = new Presentation(ResourceUtil.getResourceAsStream("…potx"));
Presentation destinationPPT = new Presentation();
ISlideCollection slides = destination.getSlides();
slides.insertClone(slides.size(), source.getSlides().get_Item(indexOfSourceSlide));

Caused by: class com.aspose.slides.exceptions.InvalidOperationException: Trying to add new cached value with the same keys.
com.aspose.slides.EffectiveDataCache.do(Unknown Source)
com.aspose.slides.char.do(Unknown Source)
com.aspose.slides.apd.for(Unknown Source)
com.aspose.slides.TextFrameFormat.while(Unknown Source)
com.aspose.slides.AutoShape.else(Unknown Source)
com.aspose.slides.Shape.finally(Unknown Source)
com.aspose.slides.Transform2DPPTXSerialization.do(Unknown Source)
com.aspose.slides.Transform2DPPTXSerialization.do(Unknown Source)
com.aspose.slides.akm.do(Unknown Source)
com.aspose.slides.qo.do(Unknown Source)
com.aspose.slides.r.do(Unknown Source)
com.aspose.slides.rr.do(Unknown Source)
com.aspose.slides.rr.do(Unknown Source)
com.aspose.slides.bj.do(Unknown Source)
com.aspose.slides.aau.if(Unknown Source)
com.aspose.slides.agq.do(Unknown Source)
com.aspose.slides.agq.do(Unknown Source)
com.aspose.slides.agf.do(Unknown Source)
com.aspose.slides.SlideCollection.addClone(Unknown Source)
com.aspose.slides.SlideCollection.addClone(Unknown Source)
com.aspose.slides.SlideCollection.addClone(Unknown Source)
com.aspose.slides.SlideCollection.insertClone(Unknown Source)

FYI … my code is multi threaded.

I have a static instance of the sourcePPT object, and one instance per thread of the destinationPPT object. And this error happens randomly, not all the time.

Thank you for the query. Unfortunately, cloning slides is not a safe operation for multi-threaded code. Please take a look at the next article: Multithreading in Aspose.Slides.

thanks for the link.
Can I have one sourcePPT Presentation and one destination PPT instance per thread (but within the same java process), so each thread has its own copy of the source Presentation to clone from. Would that cause any issues ?

With this approach, everything should work without errors.

ok thanks for the confirmation. I tried this, and it seems to be working (no NPE so far)