Skip to content

Commit

Permalink
fix: specifies encoding for net fx
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Dec 24, 2024
1 parent 5bc683b commit cd13481
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview3</Version>
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Linq;
using Microsoft.OpenApi.Models;
using System;
using System.Text;

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

0 comments on commit cd13481

Please sign in to comment.