Skip to content

Commit 548065a

Browse files
Fix Json breaking change when updating Json reference manually (#27534)
* Fix Json breaking change when updating Json reference manually * :/ * naming * ref
1 parent db04eee commit 548065a

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

src/SignalR/SignalR.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Signal
147147
EndProject
148148
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Metadata", "..\Http\Metadata\src\Microsoft.AspNetCore.Metadata.csproj", "{2E107FBB-2387-4A9F-A2CA-EFDF2E4DD64D}"
149149
EndProject
150+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Json50.Tests", "common\SignalR.Common\test-json\Microsoft.AspNetCore.SignalR.Json50.Tests.csproj", "{BFE22265-03E2-4967-B1C8-93216324D42D}"
151+
EndProject
150152
Global
151153
GlobalSection(SolutionConfigurationPlatforms) = preSolution
152154
Debug|Any CPU = Debug|Any CPU
@@ -405,6 +407,10 @@ Global
405407
{2E107FBB-2387-4A9F-A2CA-EFDF2E4DD64D}.Debug|Any CPU.Build.0 = Debug|Any CPU
406408
{2E107FBB-2387-4A9F-A2CA-EFDF2E4DD64D}.Release|Any CPU.ActiveCfg = Release|Any CPU
407409
{2E107FBB-2387-4A9F-A2CA-EFDF2E4DD64D}.Release|Any CPU.Build.0 = Release|Any CPU
410+
{BFE22265-03E2-4967-B1C8-93216324D42D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
411+
{BFE22265-03E2-4967-B1C8-93216324D42D}.Debug|Any CPU.Build.0 = Debug|Any CPU
412+
{BFE22265-03E2-4967-B1C8-93216324D42D}.Release|Any CPU.ActiveCfg = Release|Any CPU
413+
{BFE22265-03E2-4967-B1C8-93216324D42D}.Release|Any CPU.Build.0 = Release|Any CPU
408414
EndGlobalSection
409415
GlobalSection(SolutionProperties) = preSolution
410416
HideSolutionNode = FALSE
@@ -475,6 +481,7 @@ Global
475481
{FD3A8F8D-2967-4635-86FC-CC49BAF651C1} = {EDE8E45E-A5D0-4F0E-B72C-7CC14146C60A}
476482
{BB52C0FB-19FD-485A-9EBD-3FC173ECAEA0} = {9FCD621E-E710-4991-B45C-1BABC977BEEC}
477483
{2E107FBB-2387-4A9F-A2CA-EFDF2E4DD64D} = {EDE8E45E-A5D0-4F0E-B72C-7CC14146C60A}
484+
{BFE22265-03E2-4967-B1C8-93216324D42D} = {9FCD621E-E710-4991-B45C-1BABC977BEEC}
478485
EndGlobalSection
479486
GlobalSection(ExtensibilityGlobals) = postSolution
480487
SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59}

src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,14 @@ private void WriteCompletionMessage(CompletionMessage message, Utf8JsonWriter wr
508508
else if (message.HasResult)
509509
{
510510
writer.WritePropertyName(ResultPropertyNameBytes);
511-
JsonSerializer.Serialize(writer, message.Result, message.Result?.GetType(), _payloadSerializerOptions);
511+
if (message.Result == null)
512+
{
513+
writer.WriteNullValue();
514+
}
515+
else
516+
{
517+
JsonSerializer.Serialize(writer, message.Result, message.Result.GetType(), _payloadSerializerOptions);
518+
}
512519
}
513520
}
514521

@@ -522,7 +529,14 @@ private void WriteStreamItemMessage(StreamItemMessage message, Utf8JsonWriter wr
522529
WriteInvocationId(message, writer);
523530

524531
writer.WritePropertyName(ItemPropertyNameBytes);
525-
JsonSerializer.Serialize(writer, message.Item, message.Item?.GetType(), _payloadSerializerOptions);
532+
if (message.Item == null)
533+
{
534+
writer.WriteNullValue();
535+
}
536+
else
537+
{
538+
JsonSerializer.Serialize(writer, message.Item, message.Item.GetType(), _payloadSerializerOptions);
539+
}
526540
}
527541

528542
private void WriteInvocationMessage(InvocationMessage message, Utf8JsonWriter writer)
@@ -574,7 +588,14 @@ private void WriteArguments(object[] arguments, Utf8JsonWriter writer)
574588
}
575589
else
576590
{
577-
JsonSerializer.Serialize(writer, argument, type, _payloadSerializerOptions);
591+
if (argument == null)
592+
{
593+
writer.WriteNullValue();
594+
}
595+
else
596+
{
597+
JsonSerializer.Serialize(writer, argument, type, _payloadSerializerOptions);
598+
}
578599
}
579600
}
580601
writer.WriteEndArray();

src/SignalR/common/SignalR.Common/ref/Microsoft.AspNetCore.SignalR.Common.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
<Reference Include="Microsoft.Extensions.Options" />
1010
<Reference Include="System.Text.Json" />
1111
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Common.Tests" Key="" />
12+
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Json50.Tests" Key="" />
1213
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Tests.Utils" Key="" />
1314
</ItemGroup>
1415
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
1516
<Compile Include="Microsoft.AspNetCore.SignalR.Common.netcoreapp.cs" />
1617
<Reference Include="Microsoft.AspNetCore.Connections.Abstractions" />
1718
<Reference Include="Microsoft.Extensions.Options" />
1819
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Common.Tests" Key="" />
20+
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Json50.Tests" Key="" />
1921
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Tests.Utils" Key="" />
2022
</ItemGroup>
2123
</Project>

src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj

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

33
<PropertyGroup>
44
<Description>Common serialiation primitives for SignalR Clients Servers</Description>
@@ -38,6 +38,7 @@
3838

3939
<ItemGroup>
4040
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Common.Tests" />
41+
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Json50.Tests" />
4142
<InternalsVisibleTo Include="Microsoft.AspNetCore.SignalR.Tests.Utils" />
4243
</ItemGroup>
4344

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
<!-- Avoid CS1705 errors due to mix of assemblies brought in transitively. -->
6+
<CompileUsingReferenceAssemblies>false</CompileUsingReferenceAssemblies>
7+
<DisablePackageReferenceRestrictions>true</DisablePackageReferenceRestrictions>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Include="$(SignalRSharedSourceRoot)BinaryMessageFormatter.cs" Link="BinaryMessageFormatter.cs" />
12+
<Compile Include="$(SignalRSharedSourceRoot)BinaryMessageParser.cs" Link="BinaryMessageParser.cs" />
13+
<Compile Include="$(SharedSourceRoot)Buffers.Testing\**\*.cs" />
14+
<Compile Include="..\test\Internal\Protocol\JsonHubProtocolTestsBase.cs" />
15+
<Compile Include="..\test\Internal\Protocol\JsonHubProtocolTests.cs" />
16+
<Compile Include="..\test\Internal\Protocol\HubMessageHelpers.cs" />
17+
<Compile Include="..\test\Internal\Protocol\TestBinder.cs" />
18+
<Compile Include="..\test\Internal\Protocol\TestHubMessageEqualityComparer.cs" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="$(SignalRTestUtilsProject)" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Reference Include="Microsoft.AspNetCore.SignalR.Common" />
27+
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" />
28+
<PackageReference Include="System.Text.Json" Version="5.0.0" />
29+
</ItemGroup>
30+
31+
</Project>

0 commit comments

Comments
 (0)