From ce75925201a6c6c35abc6fe13c7480826aad51d4 Mon Sep 17 00:00:00 2001 From: boris324 Date: Mon, 9 Mar 2026 12:37:26 +0000 Subject: [PATCH] Fix InvalidCastException when uploading attachments as admin CipherOrganizationDetails cannot be cast to CipherDetails since CipherDetails is a subclass, not a superclass. Use pattern matching to call the appropriate ReplaceAsync overload based on runtime type. Fixes #7062 --- .../Services/Implementations/CipherService.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Core/Vault/Services/Implementations/CipherService.cs b/src/Core/Vault/Services/Implementations/CipherService.cs index 3a970d82bdff..602145cb9906 100644 --- a/src/Core/Vault/Services/Implementations/CipherService.cs +++ b/src/Core/Vault/Services/Implementations/CipherService.cs @@ -233,7 +233,14 @@ await _cipherRepository.UpdateAttachmentAsync(new CipherAttachment // Update the revision date when an attachment is added cipher.RevisionDate = DateTime.UtcNow; - await _cipherRepository.ReplaceAsync((CipherDetails)cipher); + if (cipher is CipherDetails cipherDetails) + { + await _cipherRepository.ReplaceAsync(cipherDetails); + } + else + { + await _cipherRepository.ReplaceAsync(cipher); + } await _pushService.PushSyncCipherUpdateAsync(cipher, null); @@ -287,7 +294,14 @@ public async Task CreateAttachmentAsync(Cipher cipher, Stream stream, string fil // Update the revision date when an attachment is added cipher.RevisionDate = DateTime.UtcNow; - await _cipherRepository.ReplaceAsync((CipherDetails)cipher); + if (cipher is CipherDetails cipherDetails) + { + await _cipherRepository.ReplaceAsync(cipherDetails); + } + else + { + await _cipherRepository.ReplaceAsync(cipher); + } // push await _pushService.PushSyncCipherUpdateAsync(cipher, null); @@ -898,9 +912,13 @@ private async Task DeleteAttachmentAsync(Cipher ci { await _cipherRepository.ReplaceAsync(cipher); } + else if (cipher is CipherDetails cipherDetails) + { + await _cipherRepository.ReplaceAsync(cipherDetails); + } else { - await _cipherRepository.ReplaceAsync((CipherDetails)cipher); + await _cipherRepository.ReplaceAsync(cipher); } // push