Skip to content

Add CS0677 workaround documentation using nint #48072

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

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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 22, 2025

This PR adds documentation for a potential workaround to compiler error CS0677 by using nint as an alternative to long when declaring volatile fields.

The CS0677 error occurs when attempting to use the volatile keyword with types that cannot guarantee atomic access, such as long:

class TestClass
{
   private volatile long i;   // CS0677: a volatile field cannot be of the type 'long'
}

The documentation now includes a "Potential workarounds" section that explains how nint (native-sized integer) can be used as an alternative:

class TestClass
{
   private volatile nint i;   // This compiles successfully
}

The workaround section explains:

  • How nint guarantees atomic access and works with volatile
  • Platform considerations (32-bit vs 64-bit behavior)
  • When this approach is most appropriate
  • Cross-references to related documentation about native-sized integers
  • General guidance on thread-safe programming alternatives

This addresses a gap in the documentation where developers encountering CS0677 with long had no guidance on potential solutions.

Fixes #45367.


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

Copilot AI and others added 2 commits August 22, 2025 18:12
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Missing a way to work around CS0677 Add CS0677 workaround documentation using nint Aug 22, 2025
@Copilot Copilot AI requested a review from BillWagner August 22, 2025 18:17
Copilot finished work on behalf of BillWagner August 22, 2025 18:17
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.

Missing a way to work around CS0677
2 participants