F# : Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead

412 Views Asked by At

While executing the POST or PUSH requests in Postman for the following repository (https://github.com/websharper-samples/PeopleAPI),

I am getting this error : System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. Error Screenshot

How do I set AllowSynchronousIO to true in f# to execute POST or PUSH requests for an API?

1

There are 1 best solutions below

0
On

Extremely late to the party. I had this problem with Giraffe F#. Fixed it by changing

WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(contentRoot)
    .UseIISIntegration()
    .UseWebRoot(webRoot)
    .ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureAppConfiguration)
    .Configure(Action<IApplicationBuilder> configureApp)
    .ConfigureServices(configureServices)
    .ConfigureLogging(configureLogging)
    .Build()
    .Run()

to

WebHostBuilder()
    .UseKestrel(Action<KestrelServerOptions> configKestrel)
    .UseContentRoot(contentRoot)
    .UseIISIntegration()
    .UseWebRoot(webRoot)
    .ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureAppConfiguration)
    .Configure(Action<IApplicationBuilder> configureApp)
    .ConfigureServices(configureServices)
    .ConfigureLogging(configureLogging)
    .Build()
    .Run()

and the configKestrel function looks like:

let configKestrel (opts : KestrelServerOptions) =
    opts.AllowSynchronousIO <- true