question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synchronous usage of middleware on ASP.NET Core 3.0 w/ Blazor

See original GitHub issue

Hi, I was testing new 3.0 bits and have been using this library for a long time to comply with SOAP requirements.

It throws InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

In 3.0, AllowSynchronousIO is disabled by default. See: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#allowsynchronousio-disabled

Here is the stacktrace: Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.Write(byte[] buffer, int offset, int count) System.Xml.XmlStreamNodeWriter.FlushBuffer() System.Xml.XmlStreamNodeWriter.GetBuffer(int count, out int offset) System.Xml.XmlStreamNodeWriter.UnsafeWriteUTF8Chars(Char* chars, int charCount) System.Xml.XmlUTF8NodeWriter.UnsafeWriteEscapedText(Char* chars, int count) System.Xml.XmlUTF8NodeWriter.WriteEscapedText(string s) System.Xml.XmlBaseWriter.WriteString(string value) System.Xml.XmlDictionaryAsyncCheckWriter.WriteString(string text) System.Xml.XmlWriter.WriteAttributeString(string localName, string value) SoapCore.MetaMessage.OnWriteStartEnvelope(XmlDictionaryWriter writer) System.ServiceModel.Channels.Message.WriteMessagePreamble(XmlDictionaryWriter writer) System.ServiceModel.Channels.Message.OnWriteMessageAsync(XmlDictionaryWriter writer) System.ServiceModel.Channels.Message.WriteMessageAsync(XmlDictionaryWriter writer) System.ServiceModel.Channels.TextMessageEncoderFactory+TextMessageEncoder.WriteMessageAsync(Message message, Stream stream) System.ServiceModel.Channels.TextMessageEncoderFactory+TextMessageEncoder.WriteMessageAsyncInternal(Message message, Stream stream) System.Runtime.TaskHelpers.WaitForCompletionNoSpin(Task task) System.ServiceModel.Channels.TextMessageEncoderFactory+TextMessageEncoder.WriteMessage(Message message, Stream stream) SoapCore.SoapEndpointMiddleware.ProcessMeta(HttpContext httpContext) SoapCore.SoapEndpointMiddleware.ProcessOperation(HttpContext httpContext, IServiceProvider serviceProvider) SoapCore.SoapEndpointMiddleware.Invoke(HttpContext httpContext, IServiceProvider serviceProvider) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Vaiunecommented, Sep 25, 2019

It would be better to use asynchronous APIs instead of synchronous ones. I would rather keep the default off as Microsoft recommends.

Microsoft’s recommended way to re-enable synchronous APIs is: in Program.cs configure Kestrel with the option.

                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureKestrel(serverOptions =>
                    {
                        serverOptions.AllowSynchronousIO = true;
                    });
                    webBuilder.UseStartup<Startup>();
                });
0reactions
Vaiunecommented, Jan 21, 2020

Sorry for the delay, the latest version works fine. Thanks for the implementation. Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's new in ASP.NET Core 3.0
Blazor is a new framework in ASP.NET Core for building interactive client-side web UI with .NET: Create rich interactive UIs using C# ...
Read more >
NET Core 3.0 AllowSynchronousIO Workaround
It turns out, starting in .NET Core 3.0, all synchronous operations on the request are turned off by default. AllowSynchronousIO is a option...
Read more >
10 Performance-Improvement Tips for ASP.NET Core 3.0 ...
Avoiding synchronous calling and using asynchronous instead. Optimizing data access. Using caching technology. Using response caching middleware ...
Read more >
ASP.NET Core Blazor synchronization context
Blazor uses a synchronization context (SynchronizationContext) to enforce a single logical thread of execution.
Read more >
How to use Middleware in ASP.NET Core (2 ways ... - YouTube
Use 3. UseWen 4. Map 5. MapWhen Or the second way, which is building custom middleware using middleware convention.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found