Low Performance When Cloning Master Slides from One Presentation to Another in C#

Hi,

I’m experiencing the similar issues in our project. Here are log entries and you can see that AddClone requires sometimes several seconds:

06 Nov 2025 18:24:23.072 Masters.AddClone(sourceMasterSlide) // <- ~1sec
06 Nov 2025 18:24:22.046 Masters.AddClone(sourceMasterSlide) // <- 4+ secs
06 Nov 2025 18:24:17.434 Masters.RemoveAt(0)

This is the part of the code:

    public Presentation CreateFromSlide(ISlide slide)
    {
        var sourcePresentation = slide.Presentation;

        using var targetPresentation = new Presentation();

        // remove empty slide and its master created by default
        targetPresentation.Slides.RemoveAt(0);
        _logger.LogInformation("Slides.RemoveAt(0)");
        targetPresentation.Masters.RemoveAt(0);
        _logger.LogInformation("Masters.RemoveAt(0)");

        foreach (var sourceMasterSlide in sourcePresentation.Masters)
        {
            if (targetPresentation.Masters.Any(m => m.Name == sourceMasterSlide.Name))
            {
                continue;
            }

            targetPresentation.Masters.AddClone(sourceMasterSlide);
            _logger.LogInformation("Masters.AddClone(sourceMasterSlide)");
        }

        // ...

I noticed that @id2700 's case is also happens inside the loop, however @Professionalize.Discourse provided just the simplest example… Can any loop behaviour be involved to that performance issue?

@dslynko,
Thank you for contacting free support. We are sorry you encountered this problem. Usually, cloning master slides from one presentation to another in a loop does not cause performance issues. We need more details to investigate the case. Please share the following additional files and information:

  • The sample presentation file.
  • The name and version of the operating system on which the code was executed.
  • The .NET target platform in your application project.
  • The version of Aspose.Slides you are using.