I am having this similar issue with the v6.x .NET 4.0 dll in use on WinForms.
Seems like the MergeDocument and PDFDocument classes do not release the file handles once they've loaded a file, or something related.
The error I'm having is trying to do something like load a document, append another document to it, and then save the document back to the original file.
This issue exists even in your supplied example (WinForm_Merger_MergePDFs_VB)
Place a reference to the same PDF twice or Two Different PDFs and then attempt to save the PDF to either the same PDF or to One of the Two Different PDFs and it will throw an error:
ceTe.DynamicPDF.Merger.PdfParsingException: There was end error while parsing the input PDF file. The PDF is likely corrupt or invalid. ---> System.IO.IOException: The process cannot access the file 'C:\Users\Me\Desktop\PDF\File.pdf' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at zz93.nt.c()
at zz93.nt.a()
at zz93.cm.a(hj A_0)
--- End of inner exception stack trace ---
at zz93.cm.a(hj A_0)
at zz93.dq.a(DocumentWriter A_0)
at zz93.i2.b(DocumentWriter A_0)
at ceTe.DynamicPDF.Merger.AppendedPage.a(DocumentWriter A_0, Int32 A_1, Int32 A_2)
at ceTe.DynamicPDF.Merger.AppendedPage.DrawEntries(DocumentWriter writer, Int32 pageNumber, Int32 sectionPageNumber)
at ceTe.DynamicPDF.Page.a(DocumentWriter A_0, Int32 A_1, Int32 A_2, Int32 A_3)
at zz93.oh.d(Int32 A_0)
at zz93.oh.u()
at ceTe.DynamicPDF.Document.Draw(Stream stream)
at ceTe.DynamicPDF.Document.Draw(String filePath)
at MergePDFs.Merge.button2_Click(Object sender, EventArgs e) in C:\Program Files (x86)\ceTe Software\DynamicPDF v6.0.4 for .NET\Examples\Visual Studio 2010\WinForm\WinForm_VB\Merger_MergePDFs_VB\Merge.vb:line 581
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.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
It writes a 0 byte file to the saved location, if you attempt to delete the file (system-side) it throws back the underlying error you'd get if you attempted to perform this operation again on the same 0 byte file:
The action can't be completed because the file is open in MergePDFs.exe
I kindof get where your answer is coming from, but this seems misleading and/or shouldn't open the file to write out if it is just going to effectively 0 write the file you were intending to append to... Your workaround seems to "fix" the issue, but that answer is effectively saying, "Don't use our component to append documents to an existing document", at least to me.