Skip to content

Add note about NRT runtime behavior changes in libraries #47071

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 2, 2025

The nullable reference types documentation previously gave the impression that enabling NRT would never change runtime behavior. However, libraries like Entity Framework Core use reflection to read nullable attributes and modify their behavior accordingly.

The issue:

  • Without NRT: EF Core maps reference type properties as optional in the database unless RequiredAttribute is explicitly added
  • With NRT: EF Core maps reference type properties as required in the database unless marked with nullable annotation (?)

The fix:
Added an Important callout in the "Nullable references and static analysis" section of the language reference article to clarify that while the C# compiler doesn't introduce behavior changes, other libraries may use reflection to produce different runtime behavior based on nullable annotations.

The note specifically mentions Entity Framework Core as an example, explaining that it interprets nullable references as optional values and non-nullable references as required values.

This addresses the documentation gap and helps developers understand when NRT might indirectly affect runtime behavior through library implementations.

Fixes #19633.


💡 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.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/builtin-types/nullable-reference-types.md docs/csharp/language-reference/builtin-types/nullable-reference-types

@Copilot Copilot AI changed the title [WIP] Explain when NRT *may* change runtime behavior Add note about NRT runtime behavior changes in libraries Jul 2, 2025
@Copilot Copilot AI requested a review from BillWagner July 2, 2025 14:22
Copilot finished work on behalf of BillWagner July 2, 2025 14:22
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had one wording suggestion, and then this is ready to merge

@Copilot Copilot AI requested a review from BillWagner July 3, 2025 13:49
Copilot finished work on behalf of BillWagner July 3, 2025 13:49
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@IEvangelist PTAL

@BillWagner BillWagner marked this pull request as ready for review July 3, 2025 13:57
@BillWagner BillWagner requested a review from a team as a code owner July 3, 2025 13:57
@BillWagner BillWagner enabled auto-merge (squash) July 3, 2025 13:57
@BillWagner BillWagner requested a review from IEvangelist July 3, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain when NRT *may* change runtime behavior
2 participants