diff --git a/src/Workspaces/Remote/ServiceHub/Host/AssetProvider.cs b/src/Workspaces/Remote/ServiceHub/Host/AssetProvider.cs index 75758a70003ab..479c22188a85f 100644 --- a/src/Workspaces/Remote/ServiceHub/Host/AssetProvider.cs +++ b/src/Workspaces/Remote/ServiceHub/Host/AssetProvider.cs @@ -138,6 +138,21 @@ public async ValueTask SynchronizeAssetsAsync( { if (!_assetCache.TryGetAsset(checksum, out _)) { + if (missingChecksumsCount == missingChecksums.Length) + { + // This can happen if the asset cache has been modified by another thread during this method's execution. + var newMissingChecksums = new Checksum[missingChecksumsCount * 2]; + Array.Copy(missingChecksums, newMissingChecksums, missingChecksumsCount); + + if (usePool) + { + s_checksumPool.Free(missingChecksums); + usePool = false; + } + + missingChecksums = newMissingChecksums; + } + missingChecksums[missingChecksumsCount] = checksum; missingChecksumsCount++; }