You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Initialization of StreamReader in OpenApiStreamReader throws an ArgumentNullException #1635
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
Kim-SSi commentedon May 8, 2024
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.
stephentoub commentedon May 18, 2024
On .NET Framework, StreamReader's constructor will throw an exception if
encodingis null or ifbufferSize<= 0... this call does both.