-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add ObjectDisposedException.Throw for object instance and type #58684
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
Yes please but in separate PR. |
The APIs were approved as constructors. We can't merge this with different APIs unless that's officially revisited (my comment about using static members instead was just a musing). |
FWIW, my preference is actually to do it in the same PR. That helps to validate the design of the API by seeing whether there are any places we'd like to change that can't be changed for some reason, or otherwise discovering issues with the shape of the API. That's still possible if it's rolled out separately, but only after it's already been merged, at which point we then need to go back and revise the public API, which could have already been adopted elsewhere up-stack by that point, and now we need to deal with a breaking change (within the same release). |
I don't think these arguments should be nullable (it's also not what was approved in the API review). Allowing these to be null is promoting poor usage, and the cases you highlighted are good examples of how those exceptions are lacking appropriate details for debugging because null was passed in. We wouldn't consider it breaking to pass in |
Maybe also add? public static void Throw<T>() => Throw(typeof(T)); |
I've reset the issue to api-ready-for-review to discuss the implementation-vs-spec mismatch. |
src/libraries/Common/tests/System/Net/WebSockets/WebSocketStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/src/Validation/Requires.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpContentStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ObjectDisposedException.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System/ObjectDisposedExceptionTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System/ObjectDisposedExceptionTests.cs
Outdated
Show resolved
Hide resolved
LGTM, but I defer to @stephentoub in case he has last minute second thoughts 😄 |
src/libraries/Common/tests/System/Net/WebSockets/WebSocketStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs
Outdated
Show resolved
Hide resolved
...el.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartExportProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsCloses #51700 Should I also change old calls like that
|
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpContentStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System/ObjectDisposedExceptionTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System/ObjectDisposedExceptionTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs
Outdated
Show resolved
Hide resolved
...aries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of formatting tweaks needed; otherwise this looks good. I've queued up suggestions for those formatting tweaks; I'll go ahead and commit them.
The test failure is #47968.
src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs
Outdated
Show resolved
Hide resolved
The other failure is #60706, which has been fixed in main already. |
Thank you for the contribution, @Bibletoon! Nice work and thanks for iterating through the feedback. |
Improvements on ubuntu x64 dotnet/perf-autofiling-issues#2086 |
Why/how would this change have impacted that particular benchmark? |
Closes #51700
I've decided to make static methods instead of new ctors because of breaking changes with null argument (like there and there)
Should I also change old calls like that
throw new ObjectDisposedException(GetType().FullName);
orthrow new ObjectDisposedException(GetType().Name);
to new method?