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
src/VbaCompiler/VbaCompiler.csproj - Update package reference
src/VbaCompiler/VbaCompiler.cs - Update compilation logic
src/VbaCompiler/Vba/ModuleStream.cs - Update stream writing
tests/VbaCompiler.Tests/VbaCompiler.Tests.csproj - Update package reference
tests/VbaCompiler.Tests/Streams/VbaProjectRoundTripTests.cs - Update test code
utils/vbad/vbad.csproj - Update package reference
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
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:
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:
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)CFStorageStorageCFStreamCfbStreamNote:
Storageis notIDisposablein 3.x, onlyRootStorageandCfbStreamare.Files to Modify
src/VbaCompiler/VbaCompiler.csproj- Update package referencesrc/VbaCompiler/VbaCompiler.cs- Update compilation logicsrc/VbaCompiler/Vba/ModuleStream.cs- Update stream writingtests/VbaCompiler.Tests/VbaCompiler.Tests.csproj- Update package referencetests/VbaCompiler.Tests/Streams/VbaProjectRoundTripTests.cs- Update test codeutils/vbad/vbad.csproj- Update package referenceutils/vbad/Program.cs- Update decompiler utilityBenefits of Upgrading
References