Skip to content

Commit c4021e2

Browse files
Fixing problem on Linux where dotnet run fails because we try to set an IIS config (#17903)
* Don't add a blanket rule to allow synchronous IO, should not be necessary for the new management API * Add obsolete warning * Catch errors while adding global rule to allow synchronous IO, which fails on non-windows machines * Some updates based on PR feedback
1 parent ba58c63 commit c4021e2

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Data.Common;
22
using System.Net.Http.Headers;
33
using System.Reflection;
4+
using System.Runtime.CompilerServices;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.DataProtection.Infrastructure;
67
using Microsoft.AspNetCore.Hosting;
@@ -326,12 +327,40 @@ public static IUmbracoBuilder AddHelpers(this IUmbracoBuilder builder)
326327
return builder;
327328
}
328329

329-
[Obsolete("This is not necessary any more. This will be removed in v17")]
330+
[Obsolete("This is not necessary any more. This will be removed in v16")]
330331
public static IUmbracoBuilder AddWebServer(this IUmbracoBuilder builder)
331332
{
333+
builder.Services.Configure<KestrelServerOptions>(options =>
334+
{
335+
options.AllowSynchronousIO = true;
336+
});
337+
338+
try
339+
{
340+
// See https://github.com/umbraco/Umbraco-CMS/pull/17886. This is a workaround for non-windows machines
341+
// they won't have IIS available and trying to set this option will throw an exception.
342+
//
343+
// We're deferring this call to a method because if we just try to set the options here, we still get a
344+
// TypeLoadException on non-windows machines.
345+
// This workaround came from this comment: https://stackoverflow.com/a/3346975
346+
AllowSynchronousIOForIIS(builder);
347+
}
348+
catch (TypeLoadException)
349+
{
350+
// Ignoring this exception because it's expected on non-windows machines
351+
}
332352
return builder;
333353
}
334354

355+
// Prevents the compiler from inlining the method
356+
[MethodImpl(MethodImplOptions.NoInlining)]
357+
private static void AllowSynchronousIOForIIS(IUmbracoBuilder builder) =>
358+
builder.Services.Configure<IISServerOptions>(
359+
options =>
360+
{
361+
options.AllowSynchronousIO = true;
362+
});
363+
335364
private static IProfiler GetWebProfiler(IConfiguration config, IHttpContextAccessor httpContextAccessor)
336365
{
337366
var isDebug = config.GetValue<bool>($"{Constants.Configuration.ConfigHosting}:Debug");

0 commit comments

Comments
 (0)