Commit 52bc52c
Fix hash collision in TypeMapLazyDictionary causing non-deterministic ArgumentException (#123502)
## Description
`TypeMapping.GetOrCreateExternalTypeMapping` threw non-deterministic
`ArgumentException` when type names hashed to the same value. For
example, `"Windows.Media.Devices.Core.FrameFlashControl"` and
`"Windows.Security.Credentials.PasswordCredential"` produce identical
`GetHashCode()` results, causing collision on insertion.
Root cause: `LazyExternalTypeDictionary` used `Dictionary<int,
DelayedType>` keyed by `string.GetHashCode()` instead of the string
itself.
This matches the collision-safe approach already used in
`LazyProxyTypeDictionary` but simplified since external type mappings
don't require multi-value support.
The fix addresses a design issue where hash collisions could occur. The
existing test coverage is sufficient to validate the behavior.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>1 parent 4b0b723 commit 52bc52c
File tree
1 file changed
+4
-8
lines changed- src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices
1 file changed
+4
-8
lines changedLines changed: 4 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | | - | |
322 | | - | |
| 320 | + | |
323 | 321 | | |
324 | 322 | | |
325 | 323 | | |
326 | | - | |
327 | | - | |
| 324 | + | |
328 | 325 | | |
329 | 326 | | |
330 | 327 | | |
| |||
336 | 333 | | |
337 | 334 | | |
338 | 335 | | |
339 | | - | |
340 | | - | |
| 336 | + | |
341 | 337 | | |
342 | 338 | | |
343 | 339 | | |
344 | 340 | | |
345 | | - | |
| 341 | + | |
346 | 342 | | |
347 | 343 | | |
348 | 344 | | |
| |||
0 commit comments