SpredsheetDocument.Save() InvalidOperationException (Collection was modified)
- Dominant language
- C#
- Stars
- 4.6k
- Forks
- 605
- PR merge metrics
- No merged PRs in 30d
Description
When executing SpreadsheetDocument.Save() (i.e. base class OpenXmlPackage.Save()) I'm getting the following error:
InvalidOperationException
Collection was modified; enumeration operation may not execute.
StackTrace:
[DBG]: PS ...>> $_.Exception.InnerException.StackTrace
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at DocumentFormat.OpenXml.Features.PackageFeatureBase.UpdateCachedItems()
at DocumentFormat.OpenXml.Packaging.Builder.SavePackageExtensions.SaveablePackage.Save()
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Save()
This happens only when I'm using the library in a PowerShell script.
While debugging in JetBrains Rider (on the same machine) it works OK.
It looks like something about the 'Cached Items' is handled differently when library is used after installing in
'C:\Program Files\PackageManagement\NuGet\Packages', comparing to debugging it in IDE.
Has anyone encountered this issue?
Environment:
Windows Server 2016
PowerShell 5.1
IDE: JetBrains Rider 2023.3.3
DocumentFormat.OpenXml.3.0.0
Contributor guide
Assessment
This issue has not been assessed yet.