Skip to content

Fix issues where code diverged from bcl behavior#566

Merged
SimonCropp merged 2 commits into
mainfrom
Fix-issues-where-code-diverged-from-BCL-behavior
Jun 30, 2026
Merged

Fix issues where code diverged from bcl behavior#566
SimonCropp merged 2 commits into
mainfrom
Fix-issues-where-code-diverged-from-BCL-behavior

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

No description provided.

Each polyfill below produced an observably different result from the
real .NET API it emulates; fixed to match the BCL, with a regression
test per bug that runs on both the polyfill (older TFMs) and the BCL
(newer TFMs).

Encoding / strings:
- Encoding.GetChars(ROS<byte>, Span<char>): copy only the decoded char
  count instead of the whole scratch buffer (threw/clobbered on non-ASCII)
- string.ReplaceLineEndings: handle empty input, preserve a trailing
  line ending, and recognise the full BCL set (FF/NEL/LS/PS)
- string.Join(char, ROS<string?>): treat null elements as empty (unsafe path)
- StringBuilder.Append(sb,int,int)/CopyTo: validate arguments

Date / time:
- DateTime/DateTimeOffset.AddMicroseconds: preserve sub-millisecond
  precision via AddTicks (AddMilliseconds rounds on .NET Framework)
- DateTime/DateTimeOffset/TimeSpan Microsecond & Nanosecond: correct the
  TicksPerMicrosecond constant (10, not 10,000,000) and the formula
- TimeSpan.FromDays/Hours/Minutes/Seconds/Milliseconds/Microseconds:
  throw ArgumentOutOfRangeException on overflow, accumulating in
  microseconds (decimal) so cancelling components stay in range

Collections / spans:
- Span.Sort(keys, values, Comparison): pass null keys to the comparison
- ConcurrentDictionary.GetOrAdd: validate valueFactory
- List.CopyTo(Span)/InsertRange: validate destination length / index
- EqualityComparer.Create: validate the delegate

Numbers / Convert:
- double/float.TryParse(.., provider, ..): include NumberStyles.AllowThousands
  (the BCL default) in the default-style overloads
- Convert.FromHexString (both OperationStatus overloads): correct
  charsConsumed on invalid data and give DestinationTooSmall priority
- ArgumentOutOfRangeException.ThrowIfZero: set ActualValue and message;
  fix two nint relational message strings

Reflection:
- Type.GetMethod(name, genericParameterCount, ..): argument validation
- MemberInfo.HasSameMetadataDefinitionAs(null): throw ArgumentNullException

IO / XML / compression / crypto / async:
- File.GetUnixFileMode/SetUnixFileMode: correct setuid(4)/setgid(2) mapping
- XDocument/XElement.LoadAsync(Stream): honor the XML-declared encoding
  instead of forcing UTF-8
- ZipFile.ExtractToDirectoryAsync(overwriteFiles:true): overwrite per file
  instead of deleting the whole destination directory
- RandomNumberGenerator.GetInt32: off-by-one rejection that never returned
  the maximum value
- TaskCompletionSource.TrySetCanceled(token): forward the token
- ZLibStream: document that the Adler-32 trailer is not validated
@SimonCropp SimonCropp added this to the 10.11.2 milestone Jun 30, 2026
@SimonCropp SimonCropp merged commit e20851a into main Jun 30, 2026
4 of 6 checks passed
@SimonCropp SimonCropp deleted the Fix-issues-where-code-diverged-from-BCL-behavior branch June 30, 2026 01:45
This was referenced Jun 30, 2026
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