Skip to content

Commit f94cc45

Browse files
tdykstraadegeo
andauthored
Fix partial read calls (#21999)
Co-authored-by: Andy De George <[email protected]>
1 parent ec0a3f7 commit f94cc45

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

.github/workflows/build-validation.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ jobs:
3838
- uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 #@v2
3939

4040
# Get the latest preview SDK (or sdk not installed by the runner)
41-
- name: Setup .NET Core SDK Preview
41+
- name: Setup .NET Core SDK
4242
if: ${{ env.DOTNET_DO_INSTALL == 'true' }}
4343
run: |
4444
echo "Downloading dotnet-install.ps1"
4545
Invoke-WebRequest https://raw.githubusercontent.com/dotnet/install-scripts/master/src/dotnet-install.ps1 -OutFile dotnet-install.ps1
4646
echo "Installing dotnet version ${{ env.DOTNET_INSTALLER_CHANNEL }}"
4747
.\dotnet-install.ps1 -InstallDir "c:\program files\dotnet" -Channel "${{ env.DOTNET_INSTALLER_CHANNEL }}"
48-
48+
49+
# Print dotnet info
50+
- name: Display .NET info
51+
run: |
52+
dotnet --info
53+
4954
# Install locate projs global tool
5055
- name: Install LocateProjects tool
5156
run: |

docs/standard/serialization/snippets/system-text-json-how-to/csharp/JsonConverterFactoryForStackOfT.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ public class JsonConverterForStackOfT<T> : JsonConverter<Stack<T>>
3838
public override Stack<T> Read(
3939
ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
4040
{
41-
if (reader.TokenType != JsonTokenType.StartArray || !reader.Read())
41+
if (reader.TokenType != JsonTokenType.StartArray)
4242
{
4343
throw new JsonException();
4444
}
45+
reader.Read();
4546

4647
var elements = new Stack<T>();
4748

4849
while (reader.TokenType != JsonTokenType.EndArray)
4950
{
5051
elements.Push(JsonSerializer.Deserialize<T>(ref reader, options));
5152

52-
if (!reader.Read())
53-
{
54-
throw new JsonException();
55-
}
53+
reader.Read();
5654
}
5755

5856
return elements;

docs/standard/serialization/snippets/system-text-json-how-to/csharp/SystemTextJsonSamples.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

docs/standard/serialization/snippets/system-text-json-how-to/csharp/Utf8WriterToStream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static void Run()
2222
writer.WriteString("date", DateTimeOffset.UtcNow);
2323
writer.WriteNumber("temp", 42);
2424
writer.WriteEndObject();
25+
writer.Flush();
2526

2627
string json = Encoding.UTF8.GetString(stream.ToArray());
2728
Console.WriteLine(json);

0 commit comments

Comments
 (0)