Skip to content

IDISP001 and IDISP004 false positives / add special case for MemoryStream #541

Open
@erichiller

Description

@erichiller

Use of MemoryStream triggers IDISP001 and IDISP004 however, while MemoryStream implements IDisposable it doesn't actually have disposable resources.

CA2000 has a special case for Stream types because of this. Their special cases are:

  • System.IO.Stream
  • System.IO.StringReader
  • System.IO.TextReader
  • System.IO.TextWriter
  • System.Resources.IResourceReader

It would be good if these two analyzers had the same special cases. Alternatively (and a better, more future-proofed solution) would be to have a configuration rule, ideally something matching the EditorConfig rule like CA2000's excluded_symbol_names and excluded_type_names_with_derived_types:

dotnet_code_quality.IDISPxxx.excluded_symbol_names = MyType
dotnet_code_quality.IDISPxxx.excluded_type_names_with_derived_types = MyType

Example IDISP001:

var memoryStream = new MemoryStream( "{ }"u8.ToArray() );

Example IDISP004:

var memoryStream = config.AddJsonStream( new MemoryStream( "{ }"u8.ToArray() ) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions