claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
54 stars 17 forks source link

Support for asynchronous IO in ASP.NET Core #67

Open NxSoftware opened 4 years ago

NxSoftware commented 4 years ago

First of all, great work on this library!

We're using it in an ASP.NET Core 3.x web application to parse the plist data in the request body, unfortunately as of 3.0 by default the server is configured to disallow synchronous IO operations.

This results in an InvalidOperationException from within the HttpRequestStream when attempting to copy it's contents to a MemoryStream.

System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
   at System.IO.Stream.CopyTo(Stream destination)
   at Claunia.PropertyList.PropertyListParser.ReadAll(Stream fs)
   at Claunia.PropertyList.PropertyListParser.Parse(Stream fs)

We are currently working around this by allowing synchronous IO but it seems that the preferred approach is to update the code & libraries to use async stream operations.

I realise this is likely a non-trivial change in the plist-cil code but curious to hear your thoughts about this.

claunia commented 4 years ago

Hi,

I think it would fit to create a ParseAsync() method.

If you want to do it yourself and submit a patch it is most welcome, if not I will need some time to check it.

NxSoftware commented 4 years ago

Cool, I'll try and get round to having a look at this some time this week or next.