[英]Error NU1605 when trying to run ASP.NET Core web API project
I've created an ASP.NET Core API and defined my controller as follows: 我创建了一个ASP.NET Core API,并按如下所示定义了控制器:
[Route("api/[controller]")]
[ApiController]
public class SignUpController : ControllerBase
{
private readonly DNNContext _context;
public SignUpController(DNNContext context)
{
_context = context;
var merchantSignUpResponse = PutResponse();
}
[HttpPut("{id}")]
public async Task<IActionResult> PutResultAsync(int id, [FromBody]ProPaySignUp signUp)
{
try
{
await _context.SignUpResponses.AddAsync(PutResponse());
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return Accepted();
}
public SignupResponse PutResponse()
{
string url = "https://xmltest.propay.com/api/propayapi/";
var credentials = GetCredentials();
var request = BuildMerchantData();
var restRequest = CreateRestRequest("/Signup", Method.PUT);
restRequest.AddJsonBody(request);
return Execute<SignupResponse>(restRequest, url);
}
private static RestRequest CreateRestRequest(string resource, Method method)
{
var credentials = GetCredentials();
var restRequest = new RestRequest
{
Resource = resource,
Method = method,
RequestFormat = DataFormat.Json,
};
restRequest.AddHeader("accept", "application/json");
restRequest.AddHeader("Authorization", credentials);
return restRequest;
}
private static T Execute<T>(IRestRequest request, string baseUrl) where T : class, new()
{
var client = new RestClient(baseUrl);
var response = client.Execute<T>(request);
if (response.ErrorException != null)
{
Console.WriteLine(
"Error: Exception: {0}, Headers: {1}, Content: {2}, Status Code: {3}",
response.ErrorException,
response.Headers,
response.Content,
response.StatusCode);
}
return response.Data;
}
The solution builds successfully. 解决方案成功构建。 I then Launch Postman and enter the URL
https://localhost:44381/api/SignUp
with method PUT. 然后,我启动Postman并使用方法PUT输入URL
https://localhost:44381/api/SignUp
。 I receive a message stating There was an error connecting to https://localhost:44381/api/SignUp.
我收到一条消息,指出
There was an error connecting to https://localhost:44381/api/SignUp.
I then opened a command prompt at the directory in which my project resides and executed dotnet run SOBProPayService
. 然后,我在项目所在的目录中打开命令提示符,并执行
dotnet run SOBProPayService
。 The error returned is 返回的错误是
error NU1605: Detected package downgrade: Microsoft.AspNetCore.Razor.Design from 2.2.0 to 2.1.2. Reference the package directly from the project to select a different version.
How do I resolve this error? 如何解决此错误?
I usually get this error when I have inconsistent versions of packages. 当我的软件包版本不一致时,通常会出现此错误。 Check your .csproj file for Nuget package versions, or check package manager for updated packages and update if you have some available.
检查您的.csproj文件是否包含Nuget软件包版本,或者检查软件包管理器以获取更新的软件包,如果有可用的软件包,请进行更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.