Skip to content

Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379

Open
lievendf wants to merge 1 commit into
EPPlusSoftware:develop8from
lievendf:fix/drawing-rename-removal-failure
Open

Fix KeyNotFoundException / ArgumentException on drawing rename and removal#2379
lievendf wants to merge 1 commit into
EPPlusSoftware:develop8from
lievendf:fix/drawing-rename-removal-failure

Conversation

@lievendf
Copy link
Copy Markdown
Contributor

@lievendf lievendf commented Jun 8, 2026

Problem

  1. Drawing Renaming: Renaming an ExcelDrawing updated the underlying XML but failed to synchronize the change with the parent's _drawingNames lookup dictionary. This caused subsequent lookups and Remove() calls on renamed drawings to fail with a KeyNotFoundException.
  2. Group Shape Removal: ExcelDrawingsGroup.Remove() removed drawings from the internal list but did not clean up their entries from the _drawingNames dictionary or re-index the remaining shapes, causing index desynchronization.
  3. Case Sensitivity: The _drawingNames dictionary in ExcelDrawingsGroup was case-sensitive, unlike the worksheet-level dictionary which is case-insensitive, resulting in inconsistent behavior.

Solution

  • Synchronized Renaming: Updated the ExcelDrawing.Name setter to validate uniqueness across both worksheet and group-level collections first, then update both lookup dictionaries.
  • Group Shape Re-indexing: Fixed ExcelDrawingsGroup.Remove to remove the shape's name from _drawingNames and re-index the shifted indices of the remaining drawings in the group.
  • Case-Insensitive Group Lookup: Initialized _drawingNames in ExcelDrawingsGroup with StringComparer.OrdinalIgnoreCase to align with worksheet-level drawing lookups.

Testing

Added unit tests in DrawingTest.cs to verify renaming and removal behavior for both standard and grouped drawings:

  • DrawingNameChangeAndRemovalTest
  • GroupedDrawingNameChangeAndRemovalTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants