diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index 4451320947..2070b59bb7 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -1,6 +1,7 @@ using System.Data.Common; using System.Net.Http.Headers; using System.Reflection; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection.Infrastructure; using Microsoft.AspNetCore.Hosting; @@ -326,12 +327,40 @@ public static partial class UmbracoBuilderExtensions return builder; } - [Obsolete("This is not necessary any more. This will be removed in v17")] + [Obsolete("This is not necessary any more. This will be removed in v16")] public static IUmbracoBuilder AddWebServer(this IUmbracoBuilder builder) { + builder.Services.Configure(options => + { + options.AllowSynchronousIO = true; + }); + + try + { + // See https://github.com/umbraco/Umbraco-CMS/pull/17886. This is a workaround for non-windows machines + // they won't have IIS available and trying to set this option will throw an exception. + // + // We're deferring this call to a method because if we just try to set the options here, we still get a + // TypeLoadException on non-windows machines. + // This workaround came from this comment: https://stackoverflow.com/a/3346975 + AllowSynchronousIOForIIS(builder); + } + catch (TypeLoadException) + { + // Ignoring this exception because it's expected on non-windows machines + } return builder; } + // Prevents the compiler from inlining the method + [MethodImpl(MethodImplOptions.NoInlining)] + private static void AllowSynchronousIOForIIS(IUmbracoBuilder builder) => + builder.Services.Configure( + options => + { + options.AllowSynchronousIO = true; + }); + private static IProfiler GetWebProfiler(IConfiguration config, IHttpContextAccessor httpContextAccessor) { var isDebug = config.GetValue($"{Constants.Configuration.ConfigHosting}:Debug");