Skip to content

Commit before consolidating when saving a message with removed attachments - #550

Merged
Sicos1977 merged 1 commit into
Sicos1977:masterfrom
jayhemnani9910:fix/save-after-attachment-removal
Nov 16, 2026
Merged

Sicos1977 merged 1 commit into
Sicos1977:masterfrom
jayhemnani9910:fix/save-after-attachment-removal

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Removing an attachment and saving the message fails in 6.2.1:

using var msg = new Storage.Message("EmailWithAttachments.msg", FileAccess.ReadWrite);
msg.DeleteAttachment(msg.Attachments[0]);
msg.Save("out.msg");
System.InvalidOperationException: Commit or revert the changes to a transacted storage before consolidating it.
   at OpenMcdf.RootStorage.Consolidate()
   at OpenMcdf.RootStorage.Flush(Boolean consolidate)
   at MsgReader.Outlook.Storage.Message.Save(Stream stream)

This started with the OpenMcdf 3.3.0 -> 3.4.0 update (11c4c02): 3.4.0 refuses to consolidate while changes are pending. In Save(), UpdateMessagePropertiesAfterAttachmentDeletion writes the properties stream after the last Commit(), and then Flush(true) consolidates. Committing those changes first fixes it.

Four of the existing tests cover this and fail on master with the exception above (MessageSizeProperty_UpdatedWhenExists, AttachmentsRemovedSuccessfully, RemoveAttachments, RemoveAttachmentsReducesFileSize). The workflow currently stops at "Restore dependencies", so they haven't run in CI since the update. With this change, dotnet test MsgReaderTests -f net10.0: 75 passed, 0 failed (before: 72 passed, 4 failed). MessageSizeProperty_UpdatedWhenExists now reaches its own Inconclusive branch, because the sample file has no PR_MESSAGE_SIZE.

…ments

Since OpenMcdf 3.4.0, Flush(true) throws 'Commit or revert the changes to a transacted storage before consolidating it' when changes are pending. UpdateMessagePropertiesAfterAttachmentDeletion writes the properties stream after the last Commit, so Save() threw for every message with deleted attachments. Commit those changes first.
@Sicos1977
Sicos1977 requested a balanced review from Copilot November 16, 2026 11:32
@Sicos1977
Sicos1977 removed the request for review from Copilot November 16, 2026 11:35
@Sicos1977
Sicos1977 merged commit 1d45237 into Sicos1977:master Nov 16, 2026
1 check failed
@lizcorgi

Copy link
Copy Markdown

Is there a plan to release a nuget package containing this fix?

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

Successfully merging this pull request may close these issues.

3 participants