Skip to content

Modernize Stream.ReadEx #1306

Closed
Carti-it wants to merge 3 commits into
MetacoSA:masterfrom
Carti-it:utils-readex
Closed

Modernize Stream.ReadEx #1306
Carti-it wants to merge 3 commits into
MetacoSA:masterfrom
Carti-it:utils-readex

Conversation

@Carti-it

@Carti-it Carti-it commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

On Wasabi side, I can still see some unobserved exception. I suspect that Stream.ReadEx might be another potential source of unobserved exceptions so I tried to modernize it.

Comment thread NBitcoin/Utils.cs
}
}

#if !NETSTANDARD1X

@Carti-it Carti-it Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my understanding that .NET Standard support 1.x was removed in #1243 (commit 4780a7f).

Comment thread NBitcoin/Utils.cs

return totalReadCount;
}
#else

@Carti-it Carti-it Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that .NET Standard 1.x support was removed, the following code is dead code in my opinion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1307 attempts to remove the remaining .NET Standard 1.x code

Comment thread NBitcoin/Utils.cs
//IO interruption not supported in this path.
currentReadCount = stream.Read(buffer, offset + totalReadCount, count - totalReadCount);
}
int currentReadCount = stream.ReadAsync(buffer, offset + totalReadCount, count - totalReadCount, cancellation).GetAwaiter().GetResult();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.readasync?view=net-10.0 mentions that this overload is support on:

Technology Versions
.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5, 6, 7, 8, 9, 10, 11
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

My understanding is that those are all supported platforms for NBitcoin. To be sure, I checked https://www.nuget.org/packages/NBitcoin#supportedframeworks-body-tab as well. I don't see anything missing.

btw: I considered stream.Read() method but it does not support cancellation so I use stream.ReadAsync().

@Carti-it Carti-it changed the title Stream.ReadEx Modernize Stream.ReadEx Jun 9, 2026
@NicolasDorier

Copy link
Copy Markdown
Collaborator

This code saw some shit, so I would prefer not touching what is not broken.

Why do you thing here is a source of unobserved exception?

@Carti-it

Carti-it commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Why do you thing here is a source of unobserved exception?

I found this PR WalletWasabi/WalletWasabi#8081 and #1097 which suggests so. However, that's all I know.

@Carti-it Carti-it closed this Jun 9, 2026
@Carti-it

Carti-it commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

I will try to dig more into it and if I find an actual proof, I will reopen the PR.

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