You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The root cause is the specification of incompatible NumberStyle flags here: It uses NumberStyles.AllowDecimalPoint and NumberStyles.AllowExponent and NumberStyles.AllowLeadingSign, none of which may be combined with NumberStyles.AllowHexSpecifier
In its current form, the linked call is pointless altogether: While the ostensible fix is to use onlyNumberStyles.AllowHexSpecifier, this would parse something like '10' as 16 (e.g., [bigint]::parse('10', 'allowhexspecifier'))
Omitting the call would mean that values with , are handled via the fallback to ConvertNumericThroughDouble(), as for the primitive integer types, but note that this can result in a loss of precision:
As an aside: This loss of precision already occurs due to the initial parsing via TryScanNumber() treating larger-than-[decimal] numbers as [double]; e.g., [bigint] '99999999999999999999999999999' yields 99999999999999991433150857216(!); see also:
Similarly, the ConvertNumericThroughDouble() fallback is problematic for [long] and [ulong] casts with integer string values that contain , (which the initial TryScanNumber() call doesn't recognize), e.g., [long] '9223372036854775,807'fails, because the [double] detour results in a value too large for a [long] (the input value is, in effect, [long]::MaxValue), and something like [long] '9223372036854775,000' results in a loss of precision (yields 9223372036854774784)
Expected behavior
1000
Actual behavior
An exception occurs:
InvalidArgument: Cannot convert value "1,000" to type "System.Numerics.BigInteger". Error: "With the AllowHexSpecifier bit set in the enum bit field, the only other valid bitsthat can be combined into the enum value must be a subset of those in HexNumber. (Parameter 'style')"
Prerequisites
Steps to reproduce
Note:
The root cause is the specification of incompatible
NumberStyleflags here: It usesNumberStyles.AllowDecimalPointandNumberStyles.AllowExponentandNumberStyles.AllowLeadingSign, none of which may be combined withNumberStyles.AllowHexSpecifierIn its current form, the linked call is pointless altogether: While the ostensible fix is to use only
NumberStyles.AllowHexSpecifier, this would parse something like'10'as16(e.g.,[bigint]::parse('10', 'allowhexspecifier'))Omitting the call would mean that values with
,are handled via the fallback toConvertNumericThroughDouble(), as for the primitive integer types, but note that this can result in a loss of precision:As an aside: This loss of precision already occurs due to the initial parsing via
TryScanNumber()treating larger-than-[decimal]numbers as[double]; e.g.,[bigint] '99999999999999999999999999999'yields99999999999999991433150857216(!); see also:Similarly, the
ConvertNumericThroughDouble()fallback is problematic for[long]and[ulong]casts with integer string values that contain,(which the initialTryScanNumber()call doesn't recognize), e.g.,[long] '9223372036854775,807'fails, because the[double]detour results in a value too large for a[long](the input value is, in effect,[long]::MaxValue), and something like[long] '9223372036854775,000'results in a loss of precision (yields9223372036854774784)Expected behavior
1000Actual behavior
An exception occurs:
Error details
Environment data
Visuals
No response