Removing frames throws exception now

Hi,

I got some code from you to remove all text frames from header or footers

But with Version 24.6, it get corrupted with following exception:

Aspose.Words.FileCorruptedException
  HResult=0x80131500
  Message=The document appears to be corrupted and cannot be loaded.
  Source=Aspose.Words
  StackTrace:
   at Aspose.Words.Document.(Stream , LoadOptions )
   at Aspose.Words.Document.(Stream , LoadOptions )
   at Aspose.Words.Document..ctor(Stream stream, LoadOptions loadOptions)
   at Aspose.Words.Document..ctor(Stream stream)
   at Aspose.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\D055940\source\repos\Aspose\Aspose\Form1.cs:line 50
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Aspose.Program.Main() in C:\Users\D055940\source\repos\Aspose\Aspose\Program.cs:line 19

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ArgumentException: Cannot insert a node of this type at this location.

Here is the code

Aspose.Words.License lic = new Aspose.Words.License();
lic.SetLicense("Aspose.Total.lic");

Document WordDoc = new Document("Relatorio_V1_crash.docx");

foreach (Paragraph p in WordDoc.GetChildNodes(NodeType.Paragraph, true))
{
    // Check whter paragraph is in header/footer
    if (p.GetAncestor(NodeType.HeaderFooter) != null)
    {
        // Check whether the paragraph is text frame.
        if (p.FrameFormat.IsFrame)
        {            
            p.Remove();
        }
    }
}

using (MemoryStream mem = new MemoryStream())
{
    WordDoc.Save(mem, SaveFormat.Docx);
    WordDoc = new Document(mem);
}

Relatorio_V1_crash.zip (1.0 MB)

Kind regards,
@Nachti

@Nachti
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27397

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Can you give any hint what is the reason or any workaround ?

@Nachti The issue is currently in the queue for analysis. Once analysis is done we will be able to provide you more information or a fix.

The issues you have found earlier (filed as WORDSNET-27397) have been fixed in this Aspose.Words for .NET 24.10 update also available on NuGet.