Skip to content

Conversation

tobias-tengler
Copy link
Member

@tobias-tengler tobias-tengler commented Oct 7, 2025

Fixes #8433

RuntimeMethodInfo.GetParameters is not thread-safe, but we request parameters in a variety of places during type initialization. Because of this we could end up with two different ParameterInfo instances for the same parameter, which leads to the missing dictionary key error reported in the linked issue.

This PR addresses this issue by adding a new thread-safe ITypeInspector.GetParameters() that also caches the parameter instances, similar to GetMembers.
After Feedback from Michael I also added a ParameterInfoComparer that ensures that this also works if we ever decide to make the ExtendedMethodInfo public and there's a race condition between us and the developer calling GetParameters.

@tobias-tengler tobias-tengler added the 🍒 cherry-pick Consider cherry-picking these changes into the previous major version. label Oct 7, 2025
@tobias-tengler tobias-tengler force-pushed the tte/fix-concurrent-parameterinfo-lookup branch 2 times, most recently from ab9ebd3 to 8aeee8d Compare October 7, 2025 14:54
@michaelstaib
Copy link
Member

Actually, this is not the fix :D

This would just make the window smaller.

@tobias-tengler tobias-tengler force-pushed the tte/fix-concurrent-parameterinfo-lookup branch from 8aeee8d to 778d3ba Compare October 8, 2025 15:29
@michaelstaib michaelstaib merged commit 4398123 into main Oct 8, 2025
108 checks passed
@michaelstaib michaelstaib deleted the tte/fix-concurrent-parameterinfo-lookup branch October 8, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍒 cherry-pick Consider cherry-picking these changes into the previous major version. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression] Multi-threaded access to discover types throws "The given key was not present in the dictionary" exception

2 participants