This is because of line 373 in PdfDocument.cs.
Code:
void DoSave(PdfWriter writer)
{
if (_pages == null || _pages.Count == 0)
The _pages object is not instantiated unless the Pages or PageCount property is first accessed or, the PDF is opened with a Modify flag (this explicit test performed in PdfReader.cs#L472). I noticed that even though nothing would stop someone from calling Pages.Count, the PageCount property internally calls the Pages property but only when CanModify equates to true. The page count in obtained through an alternate means when CanModify equates to false. Yet this is a bit of a moot point since the
CanModify property is hard coded to return true. Within PdfReader.cs the Modify flag is explicitly checked and under this condition _pages is created.
The only ways to avoid this error are to open the PDF stream as Modify, or access the Pages/PageCount properties at some point before saving. Perhaps it was assumed a save would never be performed unless Modify were indicated? I can think of many scenarios where a save is required without an intent of modification.
So in cases where the Modify flag was not used, should _pages have been created within a constructor or perhaps the condition should be checking Pages instead of _pages?
I know of at least one monitor that has suffered an untimely death as a result of this defect.
***EDIT***
I have submitted an issue and PR to correct it.
https://github.com/empira/PDFsharp/issues/130