Timeout exception when serializing to JSON

desautelsj's Avatar

desautelsj

28 May, 2023 02:39 PM

During my build, I have some C# code that serializes data to a JSON file with the following code:

using FileStream jsonFileStream = File.Create(...path...);
await JsonSerializer.SerializeAsync(jsonFileStream, ...my data..., typeof(...my data...), new JsonSerializerOptions { WriteIndented = true }).ConfigureAwait(false);

This works perfectly fine when running on my laptop but I get a timeout exception on AppVeyor: https://ci.appveyor.com/project/cakecontrib/cake-addindiscoverer/bu...

I tried serializing synchronously with JsonSerializer.Serialize rather than JsonSerializer.SerializeAsync but I get the same result. It works fine on my laptop but fails on AppVeyor: https://ci.appveyor.com/project/cakecontrib/cake-addindiscoverer/bu...

I tried splitting my logic into two steps: serialize to a memory stream first, and then subsequently write the content of the stream to a file. Like so:

using Stream ms = new MemoryStream();
await JsonSerializer.SerializeAsync(ms, context.Addins, typeof(AddinMetadata[]), new JsonSerializerOptions { WriteIndented = true }, cancellationToken).ConfigureAwait(false);
ms.Position = 0;


using FileStream fs = File.Create(context.AnalysisResultSaveLocation); await ms.CopyToAsync(fs).ConfigureAwait(false);

but it errors out with the same timeout exception when attempting to serialize: https://ci.appveyor.com/project/cakecontrib/cake-addindiscoverer/bu...

Admittedly, the resulting JSON is relatively large (about 30MB) so this could be a factor but I'm at a loss to explain why it works in my local environment but not in AppVeyor. Anybody has suggestions what else I could try to avoid the timeout exception?

  1. 1 Posted by desautelsj on 30 May, 2023 03:14 PM

    desautelsj's Avatar

    After a lot of trial and error, I was able to pinpoint the specific property on my model that is causing the timeout error. I excluded this property from serialization (by decorating it with [JsonIgnore]) and it solved the problem.

    I am satisfied with this solution and it allows me to move forward in my project but I still can't explain why it was a problem on AppVeyor and not on my laptop.

  2. Support Staff 2 Posted by Feodor Fitsner on 30 May, 2023 08:01 PM

    Feodor Fitsner's Avatar

    Thanks for the update!

  3. Feodor Fitsner closed this discussion on 30 Jul, 2023 09:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

13 Sep, 2023 06:05 AM
10 Sep, 2023 03:43 PM
09 Sep, 2023 05:53 PM
08 Sep, 2023 07:10 PM
31 Aug, 2023 07:59 PM
13 Aug, 2023 04:55 AM