forked from codingdna2/JsonReferenceHandlerIssue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retrofit console app as standalone repro
- Loading branch information
1 parent
dbee59a
commit c043030
Showing
2 changed files
with
21 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
using JsonReferenceHandlerIssue.WebClient; | ||
using System; | ||
using System.Threading; | ||
using JsonReferenceHandlerIssue.Controllers; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace JsonReferenceHandlerIssue.ConsoleClient | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
static async Task Main() | ||
{ | ||
var clientService = new WebClientService(new WebClientServiceSettings("https://localhost:5001", string.Empty)); | ||
|
||
Console.WriteLine("Press ESC or CTRL-C to stop"); | ||
|
||
while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape)) | ||
// referencing MVC defaults and settings from reproducing app | ||
// https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/JsonOptions.cs#L34-L40 | ||
var options = new JsonSerializerOptions(JsonSerializerDefaults.Web) | ||
{ | ||
try | ||
{ | ||
var forecast = await clientService.WeatherForecastClient.GetAsync(); | ||
} | ||
catch (System.Net.Http.HttpRequestException) | ||
{ | ||
} | ||
MaxDepth = 32, | ||
ReferenceHandler = ReferenceHandler.Preserve, | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault | ||
}; | ||
|
||
await Task.Delay(1000); | ||
var stream = new MemoryStream(); | ||
WeatherForecast[] forecasts = new WeatherForecastController(null).Get().ToArray(); | ||
|
||
while (true) | ||
{ | ||
stream.Position = 0; | ||
await JsonSerializer.SerializeAsync(stream, forecasts, options); | ||
} | ||
|
||
Console.WriteLine("Closing.."); | ||
} | ||
} | ||
} |