Fix issues where code diverged from bcl behavior#566
Merged
SimonCropp merged 2 commits intoJun 30, 2026
Conversation
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
This was referenced Jun 30, 2026
This was referenced Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.