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
This commit is contained in:
Sebastiaan Janssen
2025-01-14 01:32:43 +01:00
committed by GitHub
parent ba58c6323c
commit c4021e27e5

View File

@@ -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<KestrelServerOptions>(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<IISServerOptions>(
options =>
{
options.AllowSynchronousIO = true;
});
private static IProfiler GetWebProfiler(IConfiguration config, IHttpContextAccessor httpContextAccessor)
{
var isDebug = config.GetValue<bool>($"{Constants.Configuration.ConfigHosting}:Debug");