Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379
Open
lievendf wants to merge 1 commit into
Open
Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379lievendf wants to merge 1 commit into
lievendf wants to merge 1 commit into
Conversation
…andard/grouped drawings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ExcelDrawingupdated the underlying XML but failed to synchronize the change with the parent's_drawingNameslookup dictionary. This caused subsequent lookups andRemove()calls on renamed drawings to fail with aKeyNotFoundException.ExcelDrawingsGroup.Remove()removed drawings from the internal list but did not clean up their entries from the_drawingNamesdictionary or re-index the remaining shapes, causing index desynchronization._drawingNamesdictionary inExcelDrawingsGroupwas case-sensitive, unlike the worksheet-level dictionary which is case-insensitive, resulting in inconsistent behavior.Solution
ExcelDrawing.Namesetter to validate uniqueness across both worksheet and group-level collections first, then update both lookup dictionaries.ExcelDrawingsGroup.Removeto remove the shape's name from_drawingNamesand re-index the shifted indices of the remaining drawings in the group._drawingNamesinExcelDrawingsGroupwithStringComparer.OrdinalIgnoreCaseto align with worksheet-level drawing lookups.Testing
Added unit tests in
DrawingTest.csto verify renaming and removal behavior for both standard and grouped drawings:DrawingNameChangeAndRemovalTestGroupedDrawingNameChangeAndRemovalTest