Skip to content

Commit ea0c4dc

Browse files
authored
Merge pull request #101 from cloudscribe/jk-dev
#749 synchronous IO error
2 parents b321361 + 4bfb8b5 commit ea0c4dc

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

src/cloudscribe.Web.SiteMap.FromNavigation/cloudscribe.Web.SiteMap.FromNavigation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>cloudscribe.Web.SiteMap.FromNavigation a library that implements ISiteMapNodeService using existing tree of nodes from cloudscribe.Web.Navigation.NavigationTreeBuilderService</Description>
5-
<Version>4.1.0</Version>
5+
<Version>4.1.1</Version>
66
<Authors>Joe Audette</Authors>
77
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
88
<PackageTags>cloudscribe;mvc;sitemap</PackageTags>

src/cloudscribe.Web.SiteMap/XmlResult.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Http.Features;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.IO;
24
using System.Threading;
35
using System.Threading.Tasks;
46
using System.Xml.Linq;
@@ -25,25 +27,38 @@ public XmlResult(XDocument xml)
2527
this.ContentType = "text/xml";
2628
}
2729

28-
//public override void ExecuteResult(ActionContext context)
29-
//{
30-
// context.HttpContext.Response.ContentType = this.ContentType;
31-
// if (Xml != null)
32-
// {
33-
// Xml.Save(context.HttpContext.Response.Body, SaveOptions.DisableFormatting);
34-
// }
35-
//}
36-
37-
3830
public override async Task ExecuteResultAsync(ActionContext context)
3931
{
4032
context.HttpContext.Response.ContentType = this.ContentType;
4133

4234
if (Xml != null)
4335
{
44-
await Xml.SaveAsync(context.HttpContext.Response.Body, SaveOptions.DisableFormatting, CancellationToken.None);
45-
36+
try
37+
{
38+
// refactor to avoid IO issue below
39+
using (MemoryStream ms = new MemoryStream())
40+
{
41+
await Xml.SaveAsync(ms, SaveOptions.DisableFormatting, default(CancellationToken));
42+
ms.Seek(0, SeekOrigin.Begin);
43+
await ms.CopyToAsync(context.HttpContext.Response.Body, default(CancellationToken));
44+
}
45+
}
46+
catch
47+
{
48+
// synchronous IO disabled in Core 3.0
49+
// https://khalidabuhakmeh.com/dotnet-core-3-dot-0-allowsynchronousio-workaround
50+
// https://github.com/dotnet/aspnetcore/issues/7644
51+
52+
// workaround:
53+
var syncIOFeature = context.HttpContext.Features.Get<IHttpBodyControlFeature>();
54+
if (syncIOFeature != null)
55+
{
56+
syncIOFeature.AllowSynchronousIO = true;
57+
}
4658

59+
// old way of doing this triggered IO exception:
60+
await Xml.SaveAsync(context.HttpContext.Response.Body, SaveOptions.DisableFormatting, CancellationToken.None);
61+
}
4762
}
4863
else
4964
{

src/cloudscribe.Web.SiteMap/cloudscribe.Web.SiteMap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core controller and models for generating an xml sitemap for search indexes http://www.sitemaps.org</Description>
5-
<Version>4.1.0</Version>
5+
<Version>4.1.1</Version>
66
<Authors>Joe Audette</Authors>
77
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
88
<AssemblyName>cloudscribe.Web.SiteMap</AssemblyName>

0 commit comments

Comments
 (0)