Skip to content

Fix BinaryPrimitives float/double overloads missing when System.Memory is present - #133

Merged
Tyrrrz merged 2 commits into
primefrom
copilot/polyfills-binaryprimitives-float-double
Jul 20, 2026
Merged

Fix BinaryPrimitives float/double overloads missing when System.Memory is present#133
Tyrrrz merged 2 commits into
primefrom
copilot/polyfills-binaryprimitives-float-double

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Changes

  • PolyShim/NetCore21/BinaryPrimitives.cs: Removed the 16 float/double overloads (ReadSingle*, ReadDouble*, WriteSingle*, WriteDouble* and their Try* variants). The file now contains only integer methods and retains its original #if !FEATURE_MEMORY guard.

  • PolyShim/Net50/BinaryPrimitives.cs (new): Adds the 16 float/double overloads via C# 14 static extension members (extension(BinaryPrimitives) { ... }), guarded by #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD). This augments System.Memory's integer-only BinaryPrimitives class on pre-.NET 5 targets rather than shadowing the entire class.

  • Signatures.md: Updated the 16 float/double method entries from .NET Core 2.1 to .NET 5.0.

Method group Introduced Polyfill location
Integer read/write/reverse .NET Core 2.1 NetCore21/BinaryPrimitives.cs
Float/double read/write .NET 5.0 Net50/BinaryPrimitives.cs

@Tyrrrz

Tyrrrz commented Jul 20, 2026

Copy link
Copy Markdown
Owner

This is not the correct fix. The issue is that some of the methods were added in .NET 5 rather than .NET Core 2.1 (like the majority of them). Namely, the float/double overloads, but maybe not exclusively. These overloads are also not provided by the compatibilty packages. As such, they should be moved to the appropriate directory and have the appropriate guard attached to them. Please verify other methods too, make sure all guards are correct. Use Microsoft Docs for reference.

@copilot

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

This is not the correct fix. The issue is that some of the methods were added in .NET 5 rather than .NET Core 2.1 (like the majority of them). Namely, the float/double overloads, but maybe not exclusi...

Done in the latest commit. I verified against Microsoft Docs: the float/double overloads (ReadSingle*/ReadDouble*/WriteSingle*/WriteDouble* and their Try* variants — 16 methods) were added in .NET 5, while all integer methods (including ReverseEndianness(byte)/(sbyte)) are .NET Core 2.1.

Changes:

  • Removed the float/double methods from NetCore21/BinaryPrimitives.cs and reverted its guard to #if !FEATURE_MEMORY.
  • Added Net50/BinaryPrimitives.cs providing the float/double overloads via the extension(BinaryPrimitives) static-member pattern (like Net50/Convert.cs), guarded with #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD). This augments System.Memory's integer-only class rather than shadowing it, so integer methods stay intact.

Signatures.md regenerated confirms the split (float/double → .NET 5.0, integers → .NET Core 2.1). Builds across all TFMs and tests pass.

Copilot AI requested a review from Tyrrrz July 20, 2026 19:14
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 20, 2026 19:18
Copilot AI review requested due to automatic review settings July 20, 2026 19:18
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.19%. Comparing base (7533678) to head (2fef51a).

Additional details and impacted files
@@           Coverage Diff           @@
##            prime     #133   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files         148      148           
  Lines        3981     3981           
  Branches       87       87           
=======================================
  Hits         3949     3949           
  Misses         13       13           
  Partials       19       19           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This PR fixes missing BinaryPrimitives float/double read/write APIs on older TFMs when System.Memory is present by moving those APIs into a .NET 5–scoped polyfill layer, so they’re available on pre-.NET 5 targets without relying on System.Memory to provide them.

Changes:

  • Move ReadSingle*/ReadDouble*, WriteSingle*/WriteDouble* and corresponding Try* APIs out of the .NET Core 2.1 shim and into a .NET 5 shim implemented via static extension members.
  • Ensure the .NET 5 float/double APIs are compiled for all targets below .NET 5, and excluded on .NET 5+ where the APIs exist natively.
  • Update Signatures.md to reflect that these overloads were introduced in .NET 5.0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Signatures.md Updates API introduction version annotations for BinaryPrimitives float/double overloads to .NET 5.0.
PolyShim/NetCore21/BinaryPrimitives.cs Removes float/double overload implementations from the .NET Core 2.1 BinaryPrimitives shim.
PolyShim/Net50/BinaryPrimitives.cs Adds .NET 5 float/double overloads (and Try* variants) via static extension members for pre-.NET 5 targets.

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

Comment thread PolyShim/Net50/BinaryPrimitives.cs
@Tyrrrz

Tyrrrz commented Jul 20, 2026

Copy link
Copy Markdown
Owner

@copilot please update the PR description with an up-to-date overview of changes

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please update the PR description with an up-to-date overview of changes

Updated. Here's the current overview:

Changes

  • PolyShim/NetCore21/BinaryPrimitives.cs: Removed the 16 float/double overloads (ReadSingle*, ReadDouble*, WriteSingle*, WriteDouble* and their Try* variants). The file now contains only integer methods and retains its original #if !FEATURE_MEMORY guard.

  • PolyShim/Net50/BinaryPrimitives.cs (new): Adds the 16 float/double overloads via C# 14 static extension members (extension(BinaryPrimitives) { ... }), guarded by #if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD). This augments System.Memory's integer-only BinaryPrimitives class on pre-.NET 5 targets rather than shadowing the entire class.

  • Signatures.md: Updated the 16 float/double method entries from .NET Core 2.1 to .NET 5.0.

Method group Introduced Polyfill location
Integer read/write/reverse .NET Core 2.1 NetCore21/BinaryPrimitives.cs
Float/double read/write .NET 5.0 Net50/BinaryPrimitives.cs

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants