Skip to content

Update OpenMcdf library to version 3.1.0 #46

@jozefizso

Description

@jozefizso

Summary

Update the OpenMcdf library from version 2.4.1 to 3.1.0.

Background

The OpenMcdf library was previously upgraded to 3.1.0 in v2.0.0 but was reverted to 2.4.1 in PR #43 (v2.0.1 hotfix) because the generated macro files were invalid. The issue was that streams were not correctly mapped to folders, making the VBA project unusable.

Root Cause

The problem was a bug in OpenMcdf 3.0.x where the mini FAT was not being flushed when flushing the root storage. VBA project streams (PROJECT, PROJECTwm, _VBA_PROJECT, dir, and module streams) are typically small (<4096 bytes) and are stored in the mini FAT. Without proper mini FAT flushing, the stream data was corrupted.

Fix Available

OpenMcdf 3.1.0 (released November 17, 2025) includes the fix:

  • PR #354: "Flush mini FAT when flushing root storage"

This fix ensures the mini FAT is properly flushed when the root storage is disposed, which should resolve the corruption issue that caused the revert.

API Changes Required

OpenMcdf 3.x has a completely new API. Key changes include:

Old API (2.x) New API (3.x)
new CompoundFile() RootStorage.Create(stream, Version.V3, flags)
new CompoundFile(path) RootStorage.OpenRead(path)
storage.RootStorage.AddStream() storage.CreateStream()
storage.RootStorage.AddStorage() storage.CreateStorage()
GetStream() / GetStorage() OpenStream() / OpenStorage()
stream.SetData(bytes) stream.Write(bytes, 0, len)
stream.GetData() stream.ReadExactly(buffer)
storage.Save(stream) Automatic flush on dispose
CFStorage Storage
CFStream CfbStream

Note: Storage is not IDisposable in 3.x, only RootStorage and CfbStream are.

Files to Modify

  1. src/VbaCompiler/VbaCompiler.csproj - Update package reference
  2. src/VbaCompiler/VbaCompiler.cs - Update compilation logic
  3. src/VbaCompiler/Vba/ModuleStream.cs - Update stream writing
  4. tests/VbaCompiler.Tests/VbaCompiler.Tests.csproj - Update package reference
  5. tests/VbaCompiler.Tests/Streams/VbaProjectRoundTripTests.cs - Update test code
  6. utils/vbad/vbad.csproj - Update package reference
  7. utils/vbad/Program.cs - Update decompiler utility

Benefits of Upgrading

  • Bug fixes and improved stability
  • Better performance and reduced memory usage
  • Support for 16 TB files
  • Transaction support (commit/revert)
  • Consolidation support (reclaim space)
  • Modern .NET API with nullable annotations
  • Multi-targeting for netstandard2.0, net8.0, and net10.0

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions