Skip to content

Keep the netstandard2.0 public API available on .NET - #1736

Open
tmilnthorp wants to merge 2 commits into
angularsen:masterfrom
tmilnthorp:tmilntho/consistent-tfm-api
Open

tmilnthorp wants to merge 2 commits into
angularsen:masterfrom
tmilnthorp:tmilntho/consistent-tfm-api

Conversation

@tmilnthorp

Copy link
Copy Markdown
Collaborator

Part of #1735.

Summary

The netstandard2.0 assembly exposed public members that were missing from the .NET assemblies. A netstandard2.0 library calling them failed with MissingMethodException when used from a .NET app. This PR makes those members available on every target framework and turns on package validation so CI catches future differences.

Changes

  • Interfaces: IQuantityInfo and IQuantityInstanceInfo<TQuantity> are now public on all target frameworks. They used to be internal on .NET.
  • IQuantityOfType<TQuantity>.QuantityInfo: now exists on all target frameworks.
    • On .NET it's [Obsolete] with the same message as IQuantity.QuantityInfo, pointing to TSelf.Info.
    • IQuantity<TSelf, TUnitType> implements it once as a default interface member, so generated quantities don't change.
  • Temperature tolerance Equals: the two AffineQuantityExtensions overloads were netstandard2.0-only and now exist everywhere. On .NET, calls with Temperature arguments resolve to these non-generic overloads instead of the generic ones. Both compute the same comparison.
  • Package validation: <EnablePackageValidation>true</EnablePackageValidation> in UnitsNet.csproj.
    • CompatibilitySuppressions.xml lists the intended exceptions, with a comment explaining them: the static abstract members (Info, Create, From, Zero) and the IAdditiveIdentity constraints. These require .NET 7+ and can't exist on netstandard2.0.
    • The PR workflow already packs, so validation runs on every PR.

Not in this PR

ILogarithmicQuantity<TSelf>.LogarithmicScalingFactor is still an instance property on netstandard2.0 and a static abstract property on .NET. Package validation doesn't flag it, because it matches members by name. Fixing it means breaking either the netstandard2.0 or the .NET API, so it needs a decision first. #1735 lists the options.

Testing

  • Cross-framework repro (netstandard2.0 library used from a net10.0 app):
    • IQuantityOfType<T>.QuantityInfo and Temperature.Equals(other, tolerance): MissingMethodException on master, work with this PR.
    • LogarithmicScalingFactor: still fails, as described above.
  • Package validation: a fresh dotnet pack passes. Before this change it reported 14 errors.
  • New test: QuantityInfo_IQuantityOfTypeReference_ReturnsQuantityInfo.
  • Full UnitsNet.Tests on net10.0: 52,559 passed, 2 failed. The failures are FeetInchesTests.TryParseFeetInches with de-CH, which fail the same way on master (see Fix feet/inches parsing with apostrophe grouping #1724).

🤖 Generated with Claude Code

https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG

A library compiled against the netstandard2.0 assembly can run in an app
that loads one of the .NET assemblies, where several public members were
missing and calls failed with MissingMethodException:

- IQuantityInfo and IQuantityInstanceInfo<TQuantity> were internal on .NET
- IQuantityOfType<TQuantity>.QuantityInfo did not exist on .NET
- The Temperature tolerance Equals overloads in AffineQuantityExtensions
  only existed on netstandard2.0

These now exist on all target frameworks. IQuantityOfType.QuantityInfo is
obsolete on .NET like IQuantity.QuantityInfo, and is implemented once by
IQuantity<TSelf, TUnitType>.

Enable package validation to catch such differences in CI. The remaining
suppressions are the static abstract members and generic math
constraints, which require .NET 7 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98%. Comparing base (3bf1ef4) to head (b05e9c7).

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1736   +/-   ##
======================================
  Coverage      98%     98%           
======================================
  Files         515     515           
  Lines       24092   24093    +1     
======================================
+ Hits        23692   23693    +1     
  Misses        400     400           
Flag Coverage Δ
net48 97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

On .NET, calls with Temperature arguments now bind to the Temperature
overloads, which left the generic overloads untested. Call them from a
generic context to cover them again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG

This branch has not been deployed

No deployments
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.

1 participant