When using Save-VaultFile on some files no file object is returned, but some files might be downloaded
Issue
When using Save-VaultFile no file object is returned and the following error is logged. Some files might be downloaded.
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at powerVault.Cmdlets.Cmdlets.Vault.Facade.Files.ListExtensions.RemoveAndGet[T](IList`1 list, Func`2 predicate)
Cause
The error message is misleading. This happens when one or more files couldn't be downloaded due to Vault or Windows permissions.
You'd get this error for example if you download a drawing and one of the children on any level has its download permissions in Vault set to denied
Solution
If you are downloading into a directory that contains files already make sure to clear the existing files before downloading. Existing windows files might have write or modify restrictions or require elevated permissions.
If you are on Vault 2021 or newer it is also possible to restrict download permissions for Vault files.