代码之家  ›  专栏  ›  技术社区  ›  SidC

尝试运行ASP.NET核心web API项目时出现错误NU1605

  •  0
  • SidC  · 技术社区  · 7 年前

    我已经创建了一个ASP.NET核心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;
        }
    

    解决方案成功构建。然后我启动Postman并输入URL https://localhost:44381/api/SignUp There was an error connecting to https://localhost:44381/api/SignUp.

    然后,我在我的项目所在的目录下打开了一个命令提示符并执行了它 dotnet run SOBProPayService . 返回的错误是

    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.
    

    如何解决此错误?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Aspram    7 年前

    当我的软件包版本不一致时,通常会出现此错误。检查.csproj文件中的Nuget软件包版本,或者检查软件包管理器中的更新软件包,如果有可用的软件包,则进行更新。

    推荐文章