I am getting the error "Shape is abstract class and can't be serialized" when copying a shape from one PPT file in order to place the shape in another PPT file. The code I am using to grab the shape is as follows:
' Open presentation that contains all the shapes Dim smPres As Presentation = New Presentation(HttpContext.Current.Server.MapPath(".") + "\Templates\Sample_Master.ppt")
' Grab the proper shape from the slide that was passed in Dim smSlide As Slide = smPres.GetSlideByPosition(10) ' was 10 Dim smShape As Shape = smSlide.Shapes(1) ' was 4
' serialize the shape Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream smShape.Serialize(ms)
ms.Position = 0
' add the shape to current presentation ppPres.Slides(slideNum).Shapes.Add(ms)
smPres = Nothing
It is failing on the line "msShape.Serialize(ms)". I have included the PPT file that the shape is being copied from. The shape is on Slide 10, shape 1. It is the shape with the 3 different colored circles. It appears that their may be a problem with the shape on slide 10 itself because I am able to copy the shape that is on slide 9 using this same method.
I have worked with the code snippet shared by you and have observed that the shape that you are actually trying to serialize and raising exception is a group shape. Unfortunately, at the moment the feature of serializing the group shapes is not available. An issue with ID 3710 has already been created in our issue tracking system to further investigate and resolve the issue. This thread has also been linked with the issue so that you may be automatically notified once the issue is resolved.
For the time being, I may suggest you to try serializing every shape inside the group shape and this works for me. I have modified the code snippet for you to serve the purpose. Please share, if you may feel any issue.
' Open presentation that contains all the shapes
Dim smPres As Presentation = New Presentation("k:\Sample_Master.ppt")
' Grab the proper shape from the slide that was passed in
Dim smSlide As Slide = smPres.GetSlideByPosition(10) ' was 10
Dim smShape As Shape = smSlide.Shapes(1) ' was 4
' serialize the shape
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream
If TypeOf smShape Is GroupShape Then
Dim gShp As GroupShape = CType(smShape, GroupShape)
Dim memstream(gShp.Shapes.Count) As System.IO.MemoryStream
So when I try to add the serialized shapes to my slide using "ppPres.Slides(0).Shapes.Add(ms)" I get an error that says "Couldn't load shape from the stream". I can understand this error because "ms" doesn't have anything in it because this was a group shape and therefore we did not take the side of the Else clause where ms is set.
However, if I try to add the serialized shapes in memstream by using "ppPres.Slides(0).Shapes.Add(memstream)" it says "value of type '1-dimensional array of System.IO.Memorystream' cannot be converted to System.IO.Memorystream".
Have you used the code snippet shared by you. If you are still facing the issue then please share the project code with us for necessary investigation along with source presentation.
You already have the code. You made some modifications and said it worked for you. I tried what you sent and it does not work for me. I explained the errors I was getting, when using your code, in my previous post. There isn't anything else I can share with you. You have my code and also the ppt file that I am trying to copy the shape from.
I have worked with you issue in detail. I have generated a modified code snippet for your presentation. Actually, your group shape contains another group shape in it and for that a recursive approach has to be adopted for successful serialization of the shape. I have shared the working project code for your reference and it works for me for all slides. I am able to serialize all the shapes with no error.
However, there are few slides in presentation for which serialization is although successful but the raised exception while saving the presentation. I have re-ordered the slides in your presentation for my investigation. The new presentation is also shared along with project code. The first 8 slides of the presentations raised no issue while saving presentation. But when any of remaining 5 slides is used for serialization, the presentation failed to save. An issue with ID 26147 has been created in our issue tracking system to further investigate and resolve this issue. This thread has also been linked with the issue so that you may be automatically notified, once the issue is resolved.
Your recursive approach for serialization of the group shapes works good however I am seeing one problem. When serializing the group shape on Slide 7 in your Sample_Master2.ppt file that you sent, it is changing the bullets on the items in the shape once it adds the shape to the destination file. You can see this in the Serialize.ppt results file that you sent me. I also see it in my results after I implemented your recursive approach. It maintains the proper colors of the bullets but changes the bullet shape itself.
Thank you for the time you have spent on this. It is very appreciated.
I have observed the issue of bullet types getting changed in slide 7 and 8 of generated presentation. An issue with ID 26280 has been created in our issue tracking system to observe and resolve this issue. This thread has also been linked with the issue so that you may be automatically notified once the issue is resolved.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.