Skip to content
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

Remove "new NotImplementedExceptions" from corefx assemblies. #22069

Closed
74 tasks
ghost opened this issue May 31, 2017 · 7 comments
Closed
74 tasks

Remove "new NotImplementedExceptions" from corefx assemblies. #22069

ghost opened this issue May 31, 2017 · 7 comments
Labels
area-Meta enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration tracking This issue is tracking the completion of other related issues.
Milestone

Comments

@ghost
Copy link

ghost commented May 31, 2017

Sites found by tooling:

  • System.Net.HttpListener.DisconnectAsyncResult::AsyncState.get()

  • System.Net.HttpListener.DisconnectAsyncResult::AsyncWaitHandle.get()

  • System.Net.HttpListener.DisconnectAsyncResult::CompletedSynchronously.get()

  • System.Net.HttpListener.DisconnectAsyncResult::IsCompleted.get()

  • System.Net.WebSockets.HttpListenerWebSocketContext::CopyPrincipal(IPrincipal)

  • System.Net.WebSockets.WebSocketBase.WebSocketOperation::ProcessAction_IndicateReceiveComplete (Nullable<ArraySegment>, BufferType, Action, Buffer[], uint, IntPtr)

  • System.Net.Mime.EightBitStream::DecodeBytes(byte[], int, int)

  • System.Net.Mime.EightBitStream::EncodeBytes(byte[], int, int)

  • System.Net.Mime.EightBitStream::GetEncodedString()

  • System.Net.Mime.MimeBasePart::BeginSend(BaseWriter, AsyncCallback, bool, object)

  • System.Net.Mime.MimeBasePart::Send(BaseWriter, bool)

  • System.Runtime.Serialization.Json.ReflectionJsonReader::ReadSimpleDictionary(XmlReaderDelegator, XmlObjectSerializerReadContext, CollectionDataContract, Type, object)

  • System.Runtime.Serialization.NullPrimitiveDataContract::ReadMethodName.get()

  • System.Runtime.Serialization.NullPrimitiveDataContract::ReadXmlValue(XmlReaderDelegator, XmlObjectSerializerReadContext)

  • System.Runtime.Serialization.NullPrimitiveDataContract::WriteMethodName.get()

  • System.Runtime.Serialization.NullPrimitiveDataContract::WriteXmlElement(XmlWriterDelegator, object, XmlObjectSerializerWriteContext, XmlDictionaryString, XmlDictionaryString)

  • System.Runtime.Serialization.NullPrimitiveDataContract::WriteXmlValue(XmlWriterDelegator, object, XmlObjectSerializerWriteContext)

  • System.Runtime.Serialization.XmlDataContract::ReflectionCreateXmlSerializable(Type)

  • System.Runtime.Serialization.XmlObjectSerializerReadContext::IsBitSet(byte[], int)

  • System.ServiceModel.Channels.StreamConnection::GetCoreTransport()

  • System.ServiceModel.Dispatcher.DispatchRuntime.UnhandledActionInvoker::InvokeBegin(object, object[], AsyncCallback, object)

  • System.ServiceModel.Dispatcher.DispatchRuntime.UnhandledActionInvoker::InvokeEnd(object, object[], IAsyncResult)

  • MS.Internal.Xml.Cache.XPathDocumentBuilder::WriteEntityRef(string)

  • System.Xml.Serialization.ReflectionXmlSerializationReader::WriteArray(ArrayMapping, bool, bool, string, int, Fixup, Member)

  • System.Xml.Serialization.ReflectionXmlSerializationReader::WriteAttribute(Member, object)

  • System.Xml.Serialization.ReflectionXmlSerializationReader::WriteElement(ElementAccessor, bool, bool, bool, string, int, int, Fixup, Member)

  • System.Xml.Serialization.ReflectionXmlSerializationReader::WriteLiteralStructMethod(StructMapping, bool, bool, string)

  • System.Xml.Serialization.XmlSerializer::CreateReader()

  • System.Xml.Serialization.XmlSerializer::CreateWriter()

  • System.Xml.Serialization.XmlSerializer::Deserialize(XmlSerializationReader)

  • System.Xml.Serialization.XmlSerializer::Serialize(object, XmlSerializationWriter)

  • System.Xml.XmlRawWriter::WriteEndElementAsync(string, string, string)

  • System.Xml.XmlRawWriter::WriteNamespaceDeclarationAsync(string, string)

  • System.Xml.XmlReader::GetValueAsync()

  • System.Xml.XmlReader::ReadAsync()

  • System.Xml.XmlResolver::GetEntityAsync(Uri, string, Type)

  • System.Xml.XmlTextWriterBase64Encoder::WriteCharsAsync(char[], int, int)

  • System.Xml.XmlWellFormedWriter.NamespaceResolverProxy::System.Xml.IXmlNamespaceResolver.GetNamespacesInScope(XmlNamespaceScope)

  • System.Xml.XmlWriter::FlushAsync()

  • System.Xml.XmlWriter::WriteBase64Async(byte[], int, int)

  • System.Xml.XmlWriter::WriteCDataAsync(string)

  • System.Xml.XmlWriter::WriteCharEntityAsync(char)

  • System.Xml.XmlWriter::WriteCharsAsync(char[], int, int)

  • System.Xml.XmlWriter::WriteCommentAsync(string)

  • System.Xml.XmlWriter::WriteDocTypeAsync(string, string, string, string)

  • System.Xml.XmlWriter::WriteEndAttributeAsync()

  • System.Xml.XmlWriter::WriteEndDocumentAsync()

  • System.Xml.XmlWriter::WriteEndElementAsync()

  • System.Xml.XmlWriter::WriteEntityRefAsync(string)

  • System.Xml.XmlWriter::WriteFullEndElementAsync()

  • System.Xml.XmlWriter::WriteProcessingInstructionAsync(string, string)

  • System.Xml.XmlWriter::WriteRawAsync(char[], int, int)

  • System.Xml.XmlWriter::WriteRawAsync(string)

  • System.Xml.XmlWriter::WriteStartAttributeAsync(string, string, string)

  • System.Xml.XmlWriter::WriteStartDocumentAsync()

  • System.Xml.XmlWriter::WriteStartDocumentAsync(bool)

  • System.Xml.XmlWriter::WriteStartElementAsync(string, string, string)

  • System.Xml.XmlWriter::WriteStringAsync(string)

  • System.Xml.XmlWriter::WriteSurrogateCharEntityAsync(char, char)

  • System.Xml.XmlWriter::WriteWhitespaceAsync(string)

  • System.Xml.Xsl.XsltOld.ContainerAction::Compile(Compiler)

  • System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBuffer::EnsureHasMarshalProxy()

  • System.Security.Cryptography.DSA::DerivedClassMustOverride()

  • System.Security.Cryptography.ECDiffieHellmanPublicKey::ToXmlString()

  • System.Security.Cryptography.ECDsa::FromXmlString(string)

  • System.Security.Cryptography.ECDsa::ToXmlString(bool)

  • System.Security.Cryptography.RandomNumberGenerator::GetNonZeroBytes(byte[])

  • System.Security.Cryptography.RSA::DerivedClassMustOverride()

  • System.Security.Cryptography.AsymmetricAlgorithm::FromXmlString(string)

  • System.Security.Cryptography.AsymmetricAlgorithm::KeyExchangeAlgorithm.get()

  • System.Security.Cryptography.AsymmetricAlgorithm::SignatureAlgorithm.get()

  • System.Security.Cryptography.AsymmetricAlgorithm::ToXmlString(bool)

  • System.Transactions.InternalEnlistment::PromotableSinglePhaseNotification.get()

  • System.Transactions.InternalEnlistment::ResourceManagerIdentifier.get()

How to remove:

  1. Include the following in your .csproj file:
    <Compile Include="$(CommonPath)\System\NotImplemented.cs">
      <Link>Common\System\NotImplemented.cs</Link>
    </Compile>

Options for removing “throw new NotImplementedException()”:

If you can implement the missing functionality now:

Do so.

If this is functionality that’s not supported on a particular framework or OS, replace with

throw new PlatformNotSupportedException(SR.xxx);

If this is an api that needs to throw NotImplemented for backward compat reasons, replace with:

throw NotImplemented.ByDesign;

or

throw NotImplemented.ByDesignWithMessage(SR.xxx);

If this is a virtual api method that’s only intended to work when overridden by another class, replace with:

throw new NotSupportedException(SR.xxx);

(Unless required for backward compat, refrain from throwing NotImplemented out of these.)

If this is a virtual non-api method that’s only intended to work when overridden by another class, replace with:

An abstract method.

If this is a compiler or toolchain intrinsic that only needs a body to make C# happy:

throw new NotSupportedException();

If this is true undone work and you just can’t fix it now, replace with:

throw NotImplemented.ActiveIssue(“https://github.com/dotnet/corefx/issues/xxx”);

The string will not leak out via Exception.Message. The string is for tooling and human readers only. In the past, we’ve usually added an inline comment but the trouble with those is that IL-based tooling can’t read comments.

@ghost ghost assigned danmoseley May 31, 2017
@danmoseley
Copy link
Member

@davidsh some of these are networking. @atsushikan looks like already filtered out those that are of the form NotImplemented.ByDesignWithMessage.

I made the list into checkboxes but it seems to have iffy formatting.

@danmoseley
Copy link
Member

@atsushikan I do'nt think there is anything particular to UWP here. Although we should do this pass, I'm going to move out of that milestone as I don't think it's required to ship it. Tests should catch anything UWP specific. Let me know if I'm wrong.

@danmoseley danmoseley removed their assignment Aug 7, 2017
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@hrrrrustic
Copy link
Contributor

hrrrrustic commented May 2, 2021

@danmoseley Is this issue still relevant? (4 years after👀). I found about 200 throw new NotImplementedException() at the latest commit in main

If this is a virtual non-api method that’s only intended to work when overridden by another class, replace with:
An abstract method.

I found some cases where whole class is not abstract (for example MimeBasePart or InternalEnlistment), should it go through api design review to get abstract?

@ghost ghost added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label May 2, 2021
@danmoseley
Copy link
Member

Hmm. Many do seem to be cases where NotSupportedException should properly be thrown (cases where an interface is incompletely implemented, or a member is expected to be overridden by a derived class).

I am not sure whether that is worth changing (which would be a breaking change, albeit a relatively low risk one presumably).

I think the original goal of the opener here was to make it possible to grep for NotImplementedException and reliably know that they all represent incomplete work that deserves our attention.

@jkotas how do you feel about this goal?

@jkotas
Copy link
Member

jkotas commented May 3, 2021

I do not have a strong opinion about this.

Here are some statistics about patterns used under src/libraries:

  • throw new NotImplemetedException: 1197 instances
  • NotImplemented.ByDesign: 203 instances
  • throw new NotSupportedException: 1567 instances

So we are close to break-even between NotImplemetedException and NotSupportedException.

throw new NotImplementedException() is frequently used to mean: This is not implemented, I do not expect this method to be ever called, but it can be implemented if needed. I think it is very reasonable to use it with this meaning. For example, the recently added Json source generator added number of instances like that in https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/gen/Reflection/TypeWrapper.cs. I expect that vast majority of NotImplementedException uses in this repo fall into this category.

@danmoseley
Copy link
Member

My feeling is that it is not worth making a push here and we should encourage contributors to look at other issues.

@joperezr joperezr added the tracking This issue is tracking the completion of other related issues. label May 13, 2021
@joperezr
Copy link
Member

I agree with both comments above, so closing this issue for now. Feel free to re-open if you think this is an issue that should be addressed.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration tracking This issue is tracking the completion of other related issues.
Projects
No open projects
Development

No branches or pull requests

6 participants