Tag Archives: .Net Core

[Solved] swagger Error: Fetch errorInternal Server Error /swagger/v1/swagger.jso

When using swagger as API interface document, the following error often occurs

If this error occurs, you can take a closer look at the console,

As can be seen from the figure, ambiguous HTTP method for action is an ambiguous HTTP operation method

Check the corresponding controller and you can see that the operation feature [httppost] or [httpget] is not added. If it is added, it will be OK.

[Solved] Asp.Net Core IIS Error: HTTP Error 500.30 – ASP.NET Core app failed to start

The error message prompts you to check whether there is an error message in the system event log

check the event log and find

according to ASP Net core module – Microsoft docs shows that the default configuration is in-process hosting, which is set to inprocess. It shows that the specified web project is out of process hosting

Solution:
only the published web Change hostingmodel = “inprocess” in config file to hostingmodel = “outofprocess” or delete hostingmodel = “inprocess” directly.

[Solved] Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.


#Accident scene

In the asp.net core web API project, when reading the stream stream of request.body, the following error is reported:

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

The code is as follows:

var request = context.HttpContext.Request;
if (request.Method == "POST")
{
    request.Body.Seek(0, SeekOrigin.Begin);
    using (var reader = new StreamReader(request.Body, Encoding.UTF8))
    {
        var data = reader.ReadToEnd();
    }
}

#Solution

The synchronous reading method of the body needs to be configured in configureservices to allow synchronous reading of IO streams. Otherwise, an exception may be thrown. Call readasync or set allowsynchronous IO to true instead.
configure according to the managed service used or directly use the asynchronous reading method.

public void ConfigureServices(IServiceCollection services)
{
	//other
	
	services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
                .Configure<IISServerOptions>(x=>x.AllowSynchronousIO = true);
}

【.Net Core】using declarations‘ is not available in C# 7.3. Please use language version 8.0 or greate

introduction

in.net core3.0, the using declaration is not available in C# 7.3 after it is used in the code. Please use language version 8.0 or higher.” The solution is

error message

CS8370

0

1

2 Feature ‘using declarations is not available in C# 7.3.please use language version 8.0 or greater.

3

4

Severity

Code

Description

Project

File

Line

Suppression State

6

Error

5

6 CNPCApi

7

D:\Project\NetCore\CNPCApi\CNPCApi\Program.cs

14

Active

solution

Add the following property node

to the solution file.csproj (right-click in explorer and edit via vs open) file

<PropertyGroup>
   <LangVersion>preview</LangVersion>
</PropertyGroup>
或
<PropertyGroup>
   <LangVersion>8.0</LangVersion>
</PropertyGroup>

add after save, recompile successfully, oh