Skip to content

Read Fails with System.ArgumentNullException: 'Value cannot be null. Parameter name: encoding' #1735

@safepage

Description

@safepage

Hi, I have been using this library without issue, but when I upgraded to the latest version it crashes on Read...

Simple Example

  1. Create a new C# ConsoleApp (.Net Framework 4.8)
  2. Add Microsoft.OpenApi.Readers Nuget 1.6.15
  3. Change Main to...

`
static async Task Main(string[] args)
{
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/")
};

var stream = await httpClient.GetStreamAsync("master/examples/v3.0/petstore.yaml");

// Read V3 as YAML
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);

}
`

The issue seems to be that default (null) is passed as the encoding param in OpenApiStreamReader.Read:

public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic) { using var reader = new StreamReader(input, default, true, -1, _settings.LeaveStreamOpen); return new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic); }

This then throws in StreamReader:

public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) { if (stream == null || encoding == null) { throw new ArgumentNullException((stream == null) ? "stream" : "encoding"); }

I can't see how this can be passing any of the Reading tests?

Metadata

Metadata

Assignees

Labels

type:bugA broken experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions