Skip to content

remove Reverse extension to avoid source-breaking change with .NET 10 #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2025

Conversation

mus65
Copy link
Contributor

@mus65 mus65 commented Mar 1, 2025

The internal array Reverse extension is already a little weird because it can be ambigious with Linq's Reverse(IEnumerable<T>), but behaves differently. It changes the passed array instance instead of creating a new one and returns an array instead of an IEnumerable<T>.

.NET 10 introduces a Enumerable.Reverse<T>(T[]) which causes even more ambiguity and returns an IEnumerable<T> instead of an array, which causes some compilation errors with .NET 10:

SSH.NET/test/Renci.SshNet.Benchmarks/Common/ExtensionsBenchmarks.cs(24,26): error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Reverse<TSource>(TSource[])' and 'Renci.SshNet.Common.Extensions.Reverse<T>(T[])'
SSH.NET/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs(211,81): error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Reverse<TSource>(TSource[])' and 'Renci.SshNet.Common.Extensions.Reverse<T>(T[])'
SSH.NET/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs(224,81): error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Reverse<TSource>(TSource[])' and 'Renci.SshNet.Common.Extensions.Reverse<T>(T[])'
SSH.NET/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs(231,81): error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Reverse<TSource>(TSource[])' and 'Renci.SshNet.Common.Extensions.Reverse<T>(T[])'

Looking at the usage, the Reverseextension is only needed in the context of BigInteger which already has extension methods to deal with endianness (but which were not used everywhere). So I think it makes most sense to just remove the Reverse extension.

Also introduced a ToBigInteger(this ReadOnlySpan<byte> data) which is made use of in EcdsaKey.cs.

to avoid extra array copy on lower targets
@Rob-Hague Rob-Hague merged commit d1213cf into sshnet:develop Mar 1, 2025
3 checks passed
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.

2 participants