Skip to content

build: target only Microsoft-supported frameworks (net10.0, net11.0, netstandard2.0) - #419

Merged
ardalis merged 2 commits into
mainfrom
issue-418-update-tfms
Nov 13, 2026
Merged

ardalis merged 2 commits into
mainfrom
issue-418-update-tfms

Conversation

@ardalis

@ardalis ardalis commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Fixes #418

Summary

As of 2026-11-12 the supported .NET versions are .NET 10 (LTS) and .NET 11 (STS). .NET 8 and .NET 9 both reached end of support on 2026-11-10 (per the official releases-index.json).

Library (src/GuardClauses/GuardClauses.csproj)

  • net8.0;netstandard2.1;netstandard2.0 → net11.0;net10.0;netstandard2.0
  • netstandard2.0 is kept so .NET Framework 4.6.2–4.8.1, which Microsoft still supports, keeps working.
  • netstandard2.1 is dropped. The runtimes it uniquely served (.NET Core 3.x, .NET 5–9, Xamarin, Mono) are out of Microsoft support. There is no NETSTANDARD2_1-specific code, and remaining consumers (for example Unity) resolve the netstandard2.0 asset.

Tests

  • The test project now multi-targets net11.0;net10.0, so the full suite runs on both supported runtimes.
  • Test data fix: two GuardAgainstOutOfRangeForEnumerableDecimal cases failed on net11.0.
    • Their ClassData passed double range values that xUnit converts to decimal.
    • .NET 11 changed how it converts double to decimal: (decimal)0.1 is now 0.1000000000000000055511151231, so the in-range item 0.1m fell below the range start.
    • This is a documented .NET 11 behavioral change: Decimal and BigInteger floating-point conversions are correctly rounded (listed under "Core .NET libraries" in Breaking changes in .NET 11). See details below.
    • The library logic is correct. All range values in that file are now decimal literals, and some pre-existing trailing whitespace in the file is fixed.

CI

  • build.yml: installs the 10.x and 11.x SDKs instead of 8.x.
  • codeql-analysis.yml: adds a setup-dotnet step for 10.x and 11.x, so autobuild can build net11.0 before runner images ship the .NET 11 SDK.
  • publish.yml: SDK 6.0.x → 11.x.

Other

  • Updated the stale netstandard2.1 reference in the CallerArgumentExpressionAttribute polyfill doc comment.
  • Added .claude/skills/implement-feature (copied from another NimblePros repo and adapted for this repo's build/test/format commands) and the plan for this issue: .claude/plans/2026-11-12-issue-418-update-tfms.md.

.NET 11 double → decimal conversion change (why the test data changed)

What Microsoft's breaking-change entry says:

  • Before: converting double to decimal kept only 15 significant digits (7 for float), so (decimal)0.1 came out as 0.1.
  • From .NET 11: the exact binary value is rounded once to the nearest decimal, giving about 28 significant digits.
  • Affected APIs: the explicit cast, new decimal(double), Convert.ToDecimal, IConvertible and the generic-math conversions. The reverse direction (decimal to double/float) and BigInteger conversions changed as well.
  • No opt-out: there is no compatibility switch. If you need the old result, Microsoft suggests formatting with G15 (or G7 for float) and parsing that back to decimal.
  • Recommended fix: "Don't assume that a binary floating-point literal and a decimal literal with the same source text represent the same value." Write 0.1m, not (decimal)0.1. That's the fix applied in this PR.

Confirmed locally with a small console app doing the same conversion on both runtimes:

double value .NET 10.0.15 .NET 11.0.0
0.1 0.1 0.1000000000000000055511151231
10.1 10.1 10.099999999999999644728632120
0.3 0.3 0.2999999999999999888977697537
200.5 200.5 200.5 (exact in binary, so unchanged)

The cast, Convert.ToDecimal, Convert.ChangeType and new decimal() all gave these results. xUnit uses Convert.ChangeType to turn object[] ClassData into decimal parameters, which is why those two tests broke.

Impact on GuardClauses: the library code never converts between floating-point types and decimal (src/ has no such conversions). Only test data written as double literals was affected. The remaining casts in GuardAgainstNegativeOrZero.cs convert whole-number inputs, which are exact.

The same page also lists a related numeric change, Math.Round and MathF.Round return correctly rounded results. It doesn't affect this library.

⚠️ For the maintainer

  • This is a breaking change for net5–net9 consumers. They now resolve the netstandard2.0 asset, which doesn't include:

    • the ReadOnlySpan<char> overloads of Guard.Against.Empty / WhiteSpace (NET5_0_OR_GREATER)
    • the TryGetNonEnumeratedCount fast path

    Under NuGet guidance that calls for a major version bump (6.0.0). I left <Version> at 5.0.0 on purpose, so merging doesn't auto-publish through publish.yml. Bump the version and add release notes when you're ready to ship.

  • net10.0 and net11.0 currently compile identically. If you'd rather contributors only need the .NET 10 SDK, net10.0;netstandard2.0 would serve the same consumers.

  • dotnet format --verify-no-changes already fails on main, with about 980 pre-existing whitespace violations. I didn't reformat the whole repo; the files this PR touches pass a scoped check.

Verification

  • dotnet build -c Release: succeeded, 0 warnings, 0 errors
  • dotnet test -c Release: 959/959 passed on net10.0 and 959/959 on net11.0
  • dotnet format --verify-no-changes --include <changed .cs files>: clean
  • The packed nupkg contains only lib/net10.0, lib/net11.0 and lib/netstandard2.0
  • A separate agent with fresh context reviewed the diff. Its findings are either addressed above or listed in the plan file with the reason.
  • Note: local tests ran with the .NET 11 RC3 SDK on the 11.0 runtime. CI uses the GA 11.x SDK.

🤖 Generated with Claude Code

ardalis and others added 2 commits November 12, 2026 20:29
- Library: net8.0;netstandard2.1;netstandard2.0 -> net11.0;net10.0;netstandard2.0
  (.NET 8 and 9 reached end of support on 2026-11-10; netstandard2.0 kept for
  .NET Framework 4.6.2+)
- Tests: multi-target net11.0;net10.0
- CI: build/CodeQL install 10.x + 11.x SDKs; publish uses 11.x
- Tests: use decimal literals for decimal range test data; .NET 11's more
  precise double->decimal conversion made 0.1 != 0.1m
- Add implement-feature skill and the plan for this issue under .claude/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
Ardalis.GuardClauses 50% 87% 403 ❌
Summary 50% (295 / 591) 87% (215 / 246) 403 ❌

@ardalis
ardalis merged commit 5434b26 into main Nov 13, 2026
2 checks passed
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.

Update TFMs

1 participant