Skip to content

Commit 7a7466a

Browse files
authored
Disable interpreting of strings as DateTime during deserialization (#45891)
1 parent 82d46ca commit 7a7466a

File tree

6 files changed

+32
-35
lines changed

6 files changed

+32
-35
lines changed

src/VisualStudio/Core/Test.Next/Remote/RemoteHostClientServiceFactoryTests.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
7-
using System.Collections.Immutable;
86
using System.IO;
9-
using System.Linq;
107
using System.Reflection;
118
using System.Threading;
129
using System.Threading.Tasks;
1310
using Microsoft.CodeAnalysis;
14-
using Microsoft.CodeAnalysis.Diagnostics;
15-
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
16-
using Microsoft.CodeAnalysis.Execution;
17-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
18-
using Microsoft.CodeAnalysis.Host.Mef;
11+
using Microsoft.CodeAnalysis.CSharp.Execution;
12+
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
13+
using Microsoft.CodeAnalysis.Editor.UnitTests;
1914
using Microsoft.CodeAnalysis.Remote;
2015
using Microsoft.CodeAnalysis.Shared.TestHooks;
21-
using Microsoft.CodeAnalysis.SolutionCrawler;
2216
using Microsoft.CodeAnalysis.SymbolSearch;
2317
using Microsoft.CodeAnalysis.Test.Utilities;
18+
using Microsoft.CodeAnalysis.Test.Utilities.RemoteHost;
19+
using Microsoft.CodeAnalysis.Text;
2420
using Microsoft.VisualStudio.LanguageServices.Remote;
2521
using Roslyn.Test.Utilities.Remote;
26-
using Roslyn.Utilities;
2722
using Roslyn.VisualStudio.Next.UnitTests.Mocks;
2823
using Xunit;
2924

@@ -35,11 +30,15 @@ public class RemoteHostClientServiceFactoryTests
3530
[Fact, Trait(Traits.Feature, Traits.Features.RemoteHost)]
3631
public async Task UpdaterService()
3732
{
38-
var exportProvider = TestHostServices.CreateMinimalExportProvider();
33+
var exportProvider = ExportProviderCache
34+
.GetOrCreateExportProviderFactory(ServiceTestExportProvider.CreateAssemblyCatalog()
35+
.WithParts(typeof(InProcRemoteHostClientProvider.Factory), typeof(CSharpOptionsSerializationService)))
36+
.CreateExportProvider();
37+
3938
using var workspace = new AdhocWorkspace(TestHostServices.CreateHostServices(exportProvider));
4039

4140
var options = workspace.CurrentSolution.Options
42-
.WithChangedOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1)
41+
.WithChangedOption(Microsoft.VisualStudio.LanguageServices.Remote.RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS, 1)
4342
.WithChangedOption(Microsoft.CodeAnalysis.Test.Utilities.RemoteHost.RemoteHostOptions.RemoteHostTest, true);
4443

4544
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(options));
@@ -52,8 +51,11 @@ public async Task UpdaterService()
5251
// make sure client is ready
5352
using var client = await service.TryGetRemoteHostClientAsync(CancellationToken.None);
5453

55-
// add solution
54+
// add solution, change document
5655
workspace.AddSolution(SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default));
56+
var project = workspace.AddProject("proj", LanguageNames.CSharp);
57+
var document = workspace.AddDocument(project.Id, "doc.cs", SourceText.From("code"));
58+
workspace.ApplyTextChanges(document.Id, new[] { new TextChange(new TextSpan(0, 1), "abc") }, CancellationToken.None);
5759

5860
// wait for listener
5961
var workspaceListener = listenerProvider.GetWaiter(FeatureAttribute.Workspace);

src/Workspaces/Remote/Razor/ServiceHubServiceBase.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ protected Task<Solution> GetSolutionAsync(CancellationToken cancellationToken)
4444
}
4545

4646
public Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
47-
{
48-
var reader = solutionInfo.CreateReader();
49-
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
50-
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);
51-
52-
return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
53-
}
47+
=> GetSolutionImplAsync(solutionInfo, cancellationToken);
5448
}
5549
}

src/Workspaces/Remote/ServiceHub/ExternalAccess/Pythia/Api/PythiaServiceBase.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ protected PythiaServiceBase(IServiceProvider serviceProvider, Stream stream, IEn
2727
=> base.StartService();
2828

2929
public Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
30-
{
31-
var reader = solutionInfo.CreateReader();
32-
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
33-
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);
34-
35-
return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
36-
}
30+
=> GetSolutionImplAsync(solutionInfo, cancellationToken);
3731

3832
#pragma warning disable IDE0060 // Remove unused parameter - Avoiding breaking change in External access API
3933
protected Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken, [CallerMemberName] string? callerName = null)

src/Workspaces/Remote/ServiceHub/ExternalAccess/UnitTesting/Api/UnitTestingServiceBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44
#nullable enable
@@ -27,13 +27,7 @@ protected UnitTestingServiceBase(
2727
=> base.StartService();
2828

2929
protected Task<Solution> GetSolutionAsync(JObject solutionInfo, CancellationToken cancellationToken)
30-
{
31-
var reader = solutionInfo.CreateReader();
32-
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance } });
33-
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);
34-
35-
return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
36-
}
30+
=> GetSolutionImplAsync(solutionInfo, cancellationToken);
3731

3832
protected new Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken)
3933
=> base.RunServiceAsync(callAsync, cancellationToken);

src/Workspaces/Remote/ServiceHub/Shared/RemoteEndPoint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public RemoteEndPoint(Stream stream, TraceSource logger, object? incomingCallTar
5858

5959
var jsonFormatter = new JsonMessageFormatter();
6060

61+
// disable interpreting of strings as DateTime during deserialization:
62+
jsonFormatter.JsonSerializer.DateParseHandling = DateParseHandling.None;
63+
6164
if (jsonConverters != null)
6265
{
6366
jsonFormatter.JsonSerializer.Converters.AddRange(jsonConverters);

src/Workspaces/Remote/ServiceHub/Shared/ServiceBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading.Tasks;
1313
using Microsoft.CodeAnalysis.ErrorReporting;
1414
using Newtonsoft.Json;
15+
using Newtonsoft.Json.Linq;
1516
using Roslyn.Utilities;
1617

1718
namespace Microsoft.CodeAnalysis.Remote
@@ -87,6 +88,15 @@ protected SolutionService CreateSolutionService(PinnedSolutionInfo solutionInfo)
8788
protected Task<Solution> GetSolutionAsync(PinnedSolutionInfo solutionInfo, CancellationToken cancellationToken)
8889
=> CreateSolutionService(solutionInfo).GetSolutionAsync(solutionInfo, cancellationToken);
8990

91+
internal Task<Solution> GetSolutionImplAsync(JObject solutionInfo, CancellationToken cancellationToken)
92+
{
93+
var reader = solutionInfo.CreateReader();
94+
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Converters = new[] { AggregateJsonConverter.Instance }, DateParseHandling = DateParseHandling.None });
95+
var pinnedSolutionInfo = serializer.Deserialize<PinnedSolutionInfo>(reader);
96+
97+
return CreateSolutionService(pinnedSolutionInfo).GetSolutionAsync(pinnedSolutionInfo, cancellationToken);
98+
}
99+
90100
protected async Task<T> RunServiceAsync<T>(Func<Task<T>> callAsync, CancellationToken cancellationToken)
91101
{
92102
AssetStorage.UpdateLastActivityTime();

0 commit comments

Comments
 (0)