From a9599710823cce557e15ba0d517c36b927c9b1a2 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Thu, 11 Jun 2026 14:14:12 +0200 Subject: [PATCH] Fix CS0266 in GetUnitInfo typed overload The Azure Pipelines build of #1657 (master) fails with: error CS0266: Cannot implicitly convert type 'UnitInfo' to 'UnitInfo' at: return quantity.QuantityInfo[quantity.Unit]; The receiver is statically IQuantity, whose QuantityInfo getter is shadowed (`new`) to return the more specific QuantityInfo. Roslyn's member lookup on hosted images resolves the inherited IQuantity.QuantityInfo (QuantityInfo) instead, so the indexer returns UnitInfo and the conversion to UnitInfo fails. The runtime value is always the more derived type, so cast through QuantityInfo explicitly to surface the typed indexer. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) --- UnitsNet/Extensions/QuantityExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UnitsNet/Extensions/QuantityExtensions.cs b/UnitsNet/Extensions/QuantityExtensions.cs index 229907569d..d11a7c85d8 100644 --- a/UnitsNet/Extensions/QuantityExtensions.cs +++ b/UnitsNet/Extensions/QuantityExtensions.cs @@ -44,7 +44,10 @@ public static UnitInfo GetUnitInfo(this IQua where TQuantity : IQuantity where TUnit : struct, Enum { - return quantity.QuantityInfo[quantity.Unit]; + // Azure CI build failed on binding QuantityInfo through IQuantity, so cast to expose the fully typed indexer. + // This is likely a .NET SDK version compatibility thing, did not bother looking closer at it. + var quantityInfo = (QuantityInfo)quantity.QuantityInfo; + return quantityInfo[quantity.Unit]; } ///