Skip to content

Commit 148b830

Browse files
Adding synchronous IO enablement note
1 parent 0bdb3d1 commit 148b830

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,16 @@ To enable ASP.NET Core integration for HTTP:
719719

720720
#### JSON serialization with ASP.NET Core integration
721721

722-
ASP.NET Core has its own serialization layer, and it is not affected by [customizing general serialization configuration](#customizing-json-serialization). To customize the serialization behavior used for your HTTP triggers, you need to include an `.AddMvc()` call as part of service registration. The returned `IMvcBuilder` can be used to modify ASP.NET Core's JSON serialization settings. The following example shows how to configure JSON.NET (`Newtonsoft.Json`) for serialization using this approach:
722+
ASP.NET Core has its own serialization layer, and it is not affected by [customizing general serialization configuration](#customizing-json-serialization). To customize the serialization behavior used for your HTTP triggers, you need to include an `.AddMvc()` call as part of service registration. The returned `IMvcBuilder` can be used to modify ASP.NET Core's JSON serialization settings.
723+
724+
You can continue to use `HttpRequestData` and `HttpResponsedata` while using ASP.NET integration, though for most apps, it's better to instead use `HttpRequest` and `IActionResult`. Using `HttpRequestData`/`HttpResponseData` doesn't invoke the ASP.NET Core serialization layer and instead relies upon the [general worker serialization configuration](#customizing-json-serialization) for the app. However, when ASP.NET Core integration is enabled, you might still need to add configuration. The default behavior from ASP.NET Core is to disallow synchronous IO. To use a custom serializer that does not support asynchronous IO, such as `NewtonsoftJsonObjectSerializer`, you need to enable synchronous IO for your application by configuring the `KestrelServerOptions`.
725+
726+
The following example shows how to configure JSON.NET (`Newtonsoft.Json`) and the [Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson) for serialization using this approach:
723727
724728
# [IHostBuilder](#tab/hostbuilder)
725729

726730
```csharp
731+
using Microsoft.AspNetCore.Server.Kestrel.Core;
727732
using Microsoft.Azure.Functions.Worker;
728733
using Microsoft.Extensions.DependencyInjection;
729734
using Microsoft.Extensions.Hosting;
@@ -735,6 +740,9 @@ var host = new HostBuilder()
735740
services.AddApplicationInsightsTelemetryWorkerService();
736741
services.ConfigureFunctionsApplicationInsights();
737742
services.AddMvc().AddNewtonsoftJson();
743+
744+
// Only needed if using HttpRequestData/HttpResponseData and a serializer that doesn't support asynchronous IO
745+
// services.Configure<KestrelServerOptions>(options => options.AllowSynchronousIO = true);
738746
})
739747
.Build();
740748
host.Run();
@@ -743,6 +751,7 @@ host.Run();
743751
# [IHostApplicationBuilder](#tab/ihostapplicationbuilder)
744752

745753
```csharp
754+
using Microsoft.AspNetCore.Server.Kestrel.Core;
746755
using Microsoft.Azure.Functions.Worker;
747756
using Microsoft.Azure.Functions.Worker.Builder;
748757
using Microsoft.Extensions.DependencyInjection;
@@ -758,6 +767,9 @@ builder.Services
758767

759768
builder.Services.AddMvc().AddNewtonsoftJson();
760769

770+
// Only needed if using HttpRequestData/HttpResponseData and a serializer that doesn't support asynchronous IO
771+
// builder.Services.Configure<KestrelServerOptions>(options => options.AllowSynchronousIO = true);
772+
761773
builder.Build().Run();
762774
```
763775

0 commit comments

Comments
 (0)