Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 465d0c8

Browse files
Design review: Explicitly disable TypeNameHandling in all Json.NET usage
1 parent 377401b commit 465d0c8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Microsoft.AspNetCore.NodeServices/HostingModels/HttpNodeInstance.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ internal class HttpNodeInstance : OutOfProcessNodeInstance
2525
private static readonly Regex PortMessageRegex =
2626
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
2727

28-
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
28+
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
2929
{
30-
ContractResolver = new CamelCasePropertyNamesContractResolver()
30+
ContractResolver = new CamelCasePropertyNamesContractResolver(),
31+
TypeNameHandling = TypeNameHandling.None
3132
};
3233

3334
private readonly HttpClient _client;
@@ -58,7 +59,7 @@ private static string MakeCommandLineOptions(int port)
5859

5960
protected override async Task<T> InvokeExportAsync<T>(NodeInvocationInfo invocationInfo)
6061
{
61-
var payloadJson = JsonConvert.SerializeObject(invocationInfo, JsonSerializerSettings);
62+
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
6263
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
6364
var response = await _client.PostAsync("http://localhost:" + _portNumber, payload);
6465

@@ -85,7 +86,7 @@ protected override async Task<T> InvokeExportAsync<T>(NodeInvocationInfo invocat
8586

8687
case "application/json":
8788
var responseJson = await response.Content.ReadAsStringAsync();
88-
return JsonConvert.DeserializeObject<T>(responseJson);
89+
return JsonConvert.DeserializeObject<T>(responseJson, jsonSerializerSettings);
8990

9091
case "application/octet-stream":
9192
// Streamed responses have to be received as System.IO.Stream instances

src/Microsoft.AspNetCore.NodeServices/HostingModels/SocketNodeInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ internal class SocketNodeInstance : OutOfProcessNodeInstance
2929
{
3030
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
3131
{
32-
ContractResolver = new CamelCasePropertyNamesContractResolver()
32+
ContractResolver = new CamelCasePropertyNamesContractResolver(),
33+
TypeNameHandling = TypeNameHandling.None
3334
};
3435

3536
private readonly SemaphoreSlim _connectionCreationSemaphore = new SemaphoreSlim(1);

0 commit comments

Comments
 (0)