Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat OPC and cloning features are broken #1814

Open
ThomasBarnekow opened this issue Oct 27, 2024 · 3 comments
Open

Flat OPC and cloning features are broken #1814

ThomasBarnekow opened this issue Oct 27, 2024 · 3 comments
Assignees

Comments

@ThomasBarnekow
Copy link
Collaborator

ThomasBarnekow commented Oct 27, 2024

Describe the bug
Based on my analysis, the Flat OPC and cloning features are "broken" since v3.0.1:

  • When creating a Flat OPC document, the resulting WordprocessingDocument instances no longer have the relationship parts.
  • Cloning a WordprocessingDocument created from a Flat OPC document or string throws an OpenXmlPackageException.

To Reproduce
To reproduce, have a look at the OpenXmlSdtTests repo that I created for this purpose. I have created several xUnit-based projects that test the same features for the following versions:

  • v2.19.0, where everything works as expected,
  • v3.0.0, where everything works as expected after having made the changes related to Package being obsolete,
  • v3.0.1, where the features are first broken, and
  • v3.1.1, where the features are still broken.

Observed behavior

  1. Since v3.0.1, WordprocessingDocument instances created using WordprocessingDocument.FromFlatOpcString(xml) no longer have the relationship parts. Up to and including v3.0.0, those parts appeared.
  2. Since v3.0.1, cloning a WordprocessingDocument instance created using WordprocessingDocument.FromFlatOpcString(xml) can no longer be cloned. Calling the Clone() method or its overloads will throw an error.

Expected behavior

  1. Flat OPC documents are created correctly (as before).
  2. WordprocessingDocument instances can be cloned (as before).

Desktop (please complete the following information):

  • OS: any (tested on macOS and Windows 11)
  • Office version: any
  • .NET Target: any (tested using .NET 8 and .NET Framework 4.7.2)
  • DocumentFormat.OpenXml Version: since v3.0.1
@ThomasBarnekow
Copy link
Collaborator Author

I've tested some more, and found out the following:

  • The WordprocessingDocument.FromFlatOpcString() overloads produce WordprocessingDocument instances with different sets of package parts (at least based on what someWordprocessingDocument.GetPackage().GetParts() is showing):
    • WordprocessingDocument.FromFlatOpcString(string) produces a WordprocessingDocument instance for which streamDoc.GetPackage().GetParts() does not contain the relationship parts (as demonstrated by the previous tests).
    • WordprocessingDocument.FromFlatOpcString(string, Stream, bool) produces a WordprocessingDocument instance for which streamDoc.GetPackage().GetParts() contains the relationship parts.
  • There is a workaround that allows us to clone a WordprocessingDocument that was first created from a Flat OPC string (or XDocument). Have a look at the FromFlatOpcString(string, Stream, bool) method in V311Tests/WorkaroundTests.cs.

@ThomasBarnekow
Copy link
Collaborator Author

@twsouthwick and @mikeebowen, any thoughts on this bug?

@twsouthwick twsouthwick self-assigned this Nov 5, 2024
@twsouthwick
Copy link
Member

Thanks for the report - I reworked the creation of packages and was a little unsure of this scenario. I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants