OpenXML .docx Document Causes Error in Office Online Server Edit Mode

I am using .NET 6.0, OpenXML 2.20, and PnP.Framework 1.13 to programmatically create a .docx file from a template and upload it to SharePoint On Premise 2016 for viewing in Office Online Server 2016. The document opens fine in view mode, but editing in the browser throws an error.

Here’s the process:

A generic .docx template is broken down into multiple sections, each represented by its own .docx. Data is populated into these sections, and their contents are copied into the main template.

The populated template is saved and uploaded to SharePoint. It previews fine in view mode.

When attempting to edit in the browser, I encounter an error logged by OOS:

2024-06-11 10:29:39.15 w3wp.exe#WebWordEditor (0x20E8) 0x1750 Hosted Office Online Word Online File Open bwd3h Exception 
[Type: System.InvalidOperationException] System.InvalidOperationException: Cannot load element at current status.
   at Microsoft.Office.WordCompanion.OpenXml.ContentBlockReader.Load()
   at Microsoft.Office.Web.WordEditor.Transform.ParaContentTransform.IsSkippedReaderSupported(ContentBlockReader readerChild, Metrics metrics)
   at Microsoft.Office.Web.WordEditor.Transform.ParaContentTransform.TransformChildren(Int32 paragraphId, ContentBlockReaderStack readerStack, Int32& runCountOnFieldBegin, UInt32& runId, Boolean isBeginningOfParagraph)
   at Microsoft.Office.Web.WordEditor.Transform.ParaContentTransform.Transform(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.TopLevelTransform.TransformChildren(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.TableCellContentTransform.Transform(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.TableContentTransform.TransformTableCell(TableCellReader cellReader, Int32 cellCount, Int32 gridSpan, TableBorders tableBorders)
   at Microsoft.Office.Web.WordEditor.Transform.TableContentTransform.TransformTableOrGhostCells(TableCellReader cellReader, Int32 cellCount, TableBorders tableBorders)
   at Microsoft.Office.Web.WordEditor.Transform.TableContentTransform.TransformTableRow(TableRowReader rowReader)
   at Microsoft.Office.Web.WordEditor.Transform.TableContentTransform.Transform(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.TopLevelTransform.TransformChildren(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.BodyContentTransform.Transform(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.MainDocumentTransform.Transform(ContentBlockReader reader)
   at Microsoft.Office.Web.WordEditor.Transform.DocumentTransform.CreateTopLevelOutlines()
   at Microsoft.Office.Web.WordEditor.Transform.DocumentTransform.TransformDocument()
GUID: 26723129-6fa6-4e89-b019-68f15e2ab069

This issue does not occur if I open the document in Office 365, make a minor edit, save it, and then upload it to OOS, suggesting a compatibility or formatting issue introduced by OpenXML.

Code for Inserting Sections body into Main Document. I feel that this is the main culprit but I am not sure what to adjust here.

public static void ReplaceParagraphWithBodyContent(
    this WordprocessingDocument doc,
    Body body,
    string paragraphName)
{
    var paragraphs = doc.MainDocumentPart.Document.Body.Elements<Paragraph>();
    var targetParagraph = paragraphs.FirstOrDefault(p => p.InnerText.Equals(paragraphName, StringComparison.InvariantCultureIgnoreCase))
        ?? throw new ObjectNotFoundException($"Paragraph {paragraphName} was not found");

    if (body != null)
    {
        var elements = body.Elements()
            .Where(x => x is not SectionProperties)
            .ToArray();
        foreach (var element in elements)
        {
            doc.MainDocumentPart.Document.Body.InsertBefore(element.CloneNode(true), targetParagraph);
        }
    }
    targetParagraph.Remove();
}

What could be causing this InvalidOperationException during document loading in edit mode?
Are there known issues with OpenXML that might affect compatibility with Office Online Server?
Any insights or similar experiences would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật