简体   繁体   English

尝试运行ASP.NET Core Web API项目时出现错误NU1605

[英]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.

相关问题 NU1605 尝试发布项目时检测到 package 降级错误 - NU1605 Detected package downgrade error when try the Publish project Serilog,.NET 7,错误 NU1605(“检测到 package 降级”)和 Microsoft.NETCore.Targets - Serilog, .NET 7, error NU1605 ("detected package downgrade") and Microsoft.NETCore.Targets 如何忽略 NuGet NU1605? - How to ignore NuGet NU1605? asp.net core web api 项目不运行 - asp.net core web api project does not run 尝试从 ASP.NET Core 5 Web 应用程序运行 Api 控制器功能时找不到 404 - 404 not found when trying to run Api Controller function from ASP.NET core 5 web app 尝试访问 ASP.NET 核心 Web API 的端点时出现 HTTP 错误 404 - HTTP Error 404 when trying to access endpoint of ASP.NET core Web API ASP.NET Core 5.0 Web API 在尝试使用 HttpDelete 删除记录时抛出错误 405 - ASP.NET Core 5.0 Web API throws error 405 when trying to delete record using HttpDelete 将EntityFramework.SqlServerCompact安装到ASP.NET 5项目时出现错误NU1002 - Error NU1002 when installng EntityFramework.SqlServerCompact to ASP.NET 5 project 是否应该在 ASP.NET 核心 Web API 项目中使用托管服务,而该服务必须在发出请求之前运行? - Should a hosted service be used in an ASP.NET Core Web API project when that service has to run before requests are made? 在 Z5DA5ACF461B4EFB7E216EC8610Z ExpressB2 中无法运行 ASP.NET 内核 Web API 项目 - Unable to run the ASP.NET Core Web API project in IIS Express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM