Why some diagram page can be duplicated and some can't using Page.Copy()?

I have diagrams that I’m working with and depending on the requirements, I need to duplicate a page.
All my diagrams have multiple pages and all the foreground pages have a background page, ‘Border’ page, associated to it. When I create a demo diagram project with random shapes on two pages, one foreground and one background, then try to copy it, it’ll work just fine. But, when only switching out the vsdx file in my code to a diagram I’m working with, it throws a System.NullReferenceException when trying to save the diagram. I’m able to duplicate the page fine when I open the file in Visio and right click on the page and select Duplicate, but this is not a feasible option as I’m generating lots of diagrams and only a few of them needs a page to be duplicated.

What could be causing this issue and is there alternative to duplicating a page?

Using Aspose.Diagram (21.10.0)
Below is the sample code I was using.
Note: I had to set SrcPage.BackPage to Null before Copy() otherwise it’ll throw the same exception but at the Copy() line.

// Load License
Aspose.Diagram.License diagramLicense = new Aspose.Diagram.License();
diagramLicense.SetLicense(licFilepath);

// Load source diagram
Diagram diagram = new Diagram(vsdxFilepath);

// Get page object
Page SrcPage = diagram.Pages[0];

// It calculates max page id
int max = 0;
if (diagram.Pages.Count != 0)
    max = diagram.Pages[0].ID;
for (int i = 1; i < diagram.Pages.Count; i++)
{
    if (max < diagram.Pages[i].ID)
        max = diagram.Pages[i].ID;
}

// Set max page ID 
int MaxPageId = max;

SrcPage.BackPage = null;
Page newPage = new Page(MaxPageId + 1);
newPage.Copy(SrcPage);
newPage.BackPage = diagram.Pages.GetPage("Border");
newPage.Name = "CopyPage";
diagram.Pages.Add(newPage);

diagram.Save(dir + "Output\\OutputDiagram.vsdx", SaveFileFormat.Vsdx);

Here’s a demo diagram I’m working with, need to duplicate ‘Page-1’.
DemoDiagram.zip (289.6 KB)

@ger.vue

We have logged an issue as DIAGRAMNET-52386 in our issue tracking system for the sake of investigation. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@ger.vue
Please try the latest fix 21.10.3. We have fixed this issue in the fix.
Aspose.Diagram21.10.3.zip (4.6 MB)
Thanks.

1 Like

Thank you for getting a fix out so soon. I am having an issue of running the application with this new DLL. It is throwing an exception at Diagram diagram = new Diagram(filename).

Unhandled exception. System.ArgumentException: 'IBM437' is not a supported encoding name. 
For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter 'name') 
at System.Text.EncodingTable.InternalGetCodePageFromName(String name)
at System.Text.EncodingTable.GetCodePageFromName(String name)
at System.Text.Encoding.GetEncoding(String name)
...
...
at Aspose.Diagram.Diagram..ctor(String filename)

I removed Aspose.Diagram 21.10.0 from my package and referenced the new DLL. I’ve also tried setting Embed Interop Types to False, but still getting the exception thrown.

Is something that I’m doing wrong when trying to use the new version given?

@ger.vue

Would you please share your sample .vsdx file with us with which you are facing this exception? We will test the scenario in our environment and address it accordingly.

DemoDiagram.zip (289.6 KB)

This is the file I was trying to test version 21.10.3 with, but it’s throwing that exception for any file and not just this one. I referenced the Net4.0 Aspose.Diagram.dll for my project if that helps.

@ger.vue

The problem looks related to your specific project. Can you please try to create a sample console application and use the shared fix in it to test the scenario? In case you still notice any issue, please share your sample application with us so that we can also try to reproduce the issue. Thanks for your cooperation.

This is the sample project and it’s still throwing the exception on my machine.
DemoProject.zip (7.4 MB)

See if you can reproduce the same issue.

I’m able to get it working. Had to install System.Drawing.Common and System.Text.Encoding.CodePages packages into my project. Also had to inlcude this in my code: System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

I feel like this is a workaround since the release version doesn’t require these steps, but this will do until the next release. Thanks for the help and fix.

@ger.vue

It is nice to hear that you were able to resolve your issue. We have recorded your feedback under the ticket and will surely consider the provided information while releasing next update of the API.

The issues you have found earlier (filed as DIAGRAMNET-52386) have been fixed in this update. This message was posted using Bugs notification tool by philip.zhou