-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Document NullabilityInfoContext thread-safety constraints #12264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Documents the thread-safety limitations of System.Reflection.NullabilityInfoContext, clarifying that concurrent calls to Create can fail due to internal non-concurrent caching.
Changes:
- Added a
<threadsafe>section to theNullabilityInfoContexttype docs describing non-thread-safe behavior and recommended mitigations. - Added non-thread-safe warnings to the
<remarks>of the fourCreateoverloads (EventInfo, FieldInfo, ParameterInfo, PropertyInfo).
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
BillWagner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
NullabilityInfoContextuses a non-concurrent dictionary for internal caching, causingInvalidOperationExceptionwhenCreatemethods are called concurrently. This wasn't documented anywhere. See dotnet/runtime#100254 for the concurrency failure.Changes:
<threadsafe>section to type documentation specifying non-thread-safe behavior and recommending external synchronization for multi-threaded scenarios<threadsafe>sections to each of the fourCreatemethod overloads (EventInfo, FieldInfo, ParameterInfo, PropertyInfo) stating "This method is not thread safe"Context:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.