Skip to content

Exception When Creating Multiple Presentations and Adding Slides #3

@CaueAnjos

Description

@CaueAnjos

Description:

I've encountered a persistent bug: every time I try to create multiple presentations and add a slide to each, the program throws an exception related to conflicting relationship IDs.

Here is a minimal reproducible example:

using FileFormat.Slides;

class Program
{
    public static string OutputPath = Path.Combine(Directory.GetCurrentDirectory(), "output");

    public static int Main()
    {
        if (!Directory.Exists(OutputPath))
            Directory.CreateDirectory(OutputPath);

        List files = ["Music1", "Music2", "Music3", "Music4"];
        GeneratePresentation(files);
        return 0;
    }

    private static void GeneratePresentation(List files)
    {
        foreach (string file in files)
        {
            Presentation p = Presentation.Create(Path.Combine(OutputPath, $"{file}.pptx"));

            Slide titleSlide = new Slide()
            {
                TextShapes = [new TextShape() { Text = file, FontSize = 66 }],
            };

            p.AppendSlide(titleSlide);
            p.Save();
            Console.WriteLine($"Made presentation for {file}");
        }
    }
}

Observed Output:

Made presentation for Music1
Unhandled exception. FileFormat.Slides.Common.FileFormatException: Error in Operation Initializing slide at FileFormat.Slides: Id conflicts with the Id of an
existing relationship. (Parameter 'id')
 Inner Exception: N/A
 ---> System.ArgumentException: Id conflicts with the Id of an existing relationship. (Parameter 'id')
   at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddNewPartInternal[T](String contentType, String id)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddNewPart[T](String id)
   at FileFormat.Slides.Facade.SlideFacade..ctor(Boolean isNewSlide)
   at FileFormat.Slides.Slide..ctor()
   --- End of inner exception stack trace ---
   at FileFormat.Slides.Slide..ctor()
   at Program.GeneratePresentation(List`1 files) in D:\Projects\TestSlides\Program.cs:line 23
   at Program.Main() in D:\Projects\TestSlides\Program.cs:line 13

Steps to Reproduce:

  1. Run the code above.
  2. Observe that the first presentation is created successfully.
  3. On the second iteration, the exception is thrown when adding a slide.

Expected Behavior:

Each presentation file should be created independently, each with its own slide. No exceptions should occur.

Actual Behavior:

The first presentation is created, but subsequent presentations throw an exception related to ID conflicts in relationships.

Question:

Am I using the library incorrectly, or is this a bug? If it is a bug, could you suggest a workaround or fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions