Fix TypeFactory.CreateCSharpType re-entrant crash on self-referencing models#10032
Open
haiyuazhang wants to merge 1 commit intomainfrom
Open
Fix TypeFactory.CreateCSharpType re-entrant crash on self-referencing models#10032haiyuazhang wants to merge 1 commit intomainfrom
haiyuazhang wants to merge 1 commit intomainfrom
Conversation
… models Self-referencing models (e.g. QueryFilter with 'and: QueryFilter[]') cause CreateCSharpTypeCore to recursively call CreateCSharpType for the same InputType. The inner call adds the type to TypeCache via Add(), then the outer call's Add() throws 'An item with the same key has already been added'. Replace Dictionary.Add() with indexer assignment which is idempotent — both calls resolve to the same type, so the second write is a safe no-op. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
Member
|
should not we refine the flow so that every time we have updated the cache first? |
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.
Summary
Fixes #10031
Self-referencing models (e.g.
QueryFilterwithand: QueryFilter[]) causeTypeFactory.CreateCSharpTypeto crash withSystem.ArgumentException: An item with the same key has already been added. This is because recursive property resolution triggers re-entrant calls thatDictionary.Add()cannot handle.Change
One-line fix in
TypeFactory.cs: replaceTypeCache.Add(inputType, type)withTypeCache[inputType] = type.The indexer assignment is idempotent — when the inner (re-entrant) call adds the cache entry first, the outer call simply overwrites with the identical value.
Call Flow (before fix)
Regression Testing
All existing tests pass with zero regressions: