Skip to content

Initialization of StreamReader in OpenApiStreamReader throws an ArgumentNullException #1635

Closed

Description

Describe the bug
Initialization of StreamReader in OpenApiStreamReader throws an ArgumentNullException in version 1.6.14.

To Reproduce
The behavior can be reproduced by calling OpenApiStreamReader.ReadAsync() from within a .NET source generator. The exception is thrown when the source generator is run.

The bug seems to be related to this commit 9a47cb2 where the StreamReader constructor is changed. Version 1.6.13 did not have the same behavior.

To verify, the same behavior can be reproduced by simply loading a file from within a .NET source generator passing a null-value encoding to the StreamReader in the same manner as is done inside OpenApiStreamReader.ReadAsync():

var reader = new StreamReader(inputStream, encoding: default, detectEncodingFromByteOrderMarks: true, bufferSize: -1, leaveOpen: false);

Additional context
OAS documents are loaded from an external stream from within a .NET source generator.
The exception is thrown when the compiler invokes the source generator, making the source generator fail.
The Visual Studio version is 17.9.3
The source generator targets netstandard2.0
The project that uses the source generator targets .net8

Activity

  1. added
    priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days
    on Apr 26, 2024
  2. Kim-SSi commented on May 8, 2024

    @Kim-SSi

    Another data point is that my net8.0-windows unit test worked where the net48 unit test failed after upgrading from 1.6.13 to 1.6.14.

  3. stephentoub commented on May 18, 2024

    @stephentoub
    Member

    On .NET Framework, StreamReader's constructor will throw an exception if encoding is null or if bufferSize <= 0... this call does both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions