Skip to content

Commit 95dafe6

Browse files
authored
Merge pull request #2026 from microsoft/fix/null-encoding
fix: specifies encoding for net fx
2 parents 79336f6 + cd13481 commit 95dafe6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
4+
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
45
<LangVersion>latest</LangVersion>
56
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
67
<Version>2.0.0-preview3</Version>

src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Linq;
1313
using Microsoft.OpenApi.Models;
1414
using System;
15+
using System.Text;
1516

1617
namespace Microsoft.OpenApi.Readers
1718
{
@@ -53,7 +54,13 @@ public ReadResult Read(MemoryStream input,
5354
// Parse the YAML text in the stream into a sequence of JsonNodes
5455
try
5556
{
57+
#if NET
58+
// this represents net core, net5 and up
5659
using var stream = new StreamReader(input, default, true, -1, settings.LeaveStreamOpen);
60+
#else
61+
// the implementation differs and results in a null reference exception in NETFX
62+
using var stream = new StreamReader(input, Encoding.UTF8, true, 4096, settings.LeaveStreamOpen);
63+
#endif
5764
jsonNode = LoadJsonNodesFromYamlDocument(stream);
5865
}
5966
catch (JsonException ex)

0 commit comments

Comments
 (0)